zoukankan      html  css  js  c++  java
  • Django urls.py报错: raise TypeError('view must be a callable or a list/tuple in the case of include()

    Django urls.py报错:

    raise TypeError('view must be a callable or a list/tuple in the case of include()

    报错信息

    "F:PyCharm 2016.2.2in unnerw.exe" C:UsersAdministratorAppDataLocalProgramsPythonPython35python.exe F:/Django/blogs/manage.py runserver 8000
    Performing system checks...

    Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000000B2A48F4950>
    Traceback (most recent call last):
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangoutilsautoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangocoremanagementcommands unserver.py", line 121, in inner_run
    self.check(display_num_errors=True)
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangocoremanagementase.py", line 374, in check
    include_deployment_checks=include_deployment_checks,
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangocoremanagementase.py", line 361, in _run_checks
    return checks.run_checks(**kwargs)
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangocorechecks egistry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangocorechecksurls.py", line 14, in check_url_config
    return check_resolver(resolver)
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangocorechecksurls.py", line 24, in check_resolver
    for pattern in resolver.url_patterns:
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangoutilsfunctional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangourls esolvers.py", line 313, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangoutilsfunctional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangourls esolvers.py", line 306, in urlconf_module
    return import_module(self.urlconf_name)
    File "C:UsersAdministratorAppDataLocalProgramsPythonPython35libimportlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 986, in _gcd_import
    File "<frozen importlib._bootstrap>", line 969, in _find_and_load
    File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 665, in exec_module
    File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
    File "F:Djangologslogsurls.py", line 26, in <module>
    url(r'^backend/', include('backend.urls')),
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangoconfurls\__init__.py", line 50, in include
    urlconf_module = import_module(urlconf_module)
    File "C:UsersAdministratorAppDataLocalProgramsPythonPython35libimportlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 986, in _gcd_import
    File "<frozen importlib._bootstrap>", line 969, in _find_and_load
    File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 665, in exec_module
    File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
    File "F:Djangologsackendurls.py", line 13, in <module>
    url(r'^editarticle-(?P<nid>d+).html$',user.editarticle),
    File "C:UsersAdministratorAppDataRoamingPythonPython35site-packagesdjangoconfurls\__init__.py", line 85, in url
    raise TypeError('view must be a callable or a list/tuple in the case of include().')
    TypeError: view must be a callable or a list/tuple in the case of include().

    解决方案:

    The `urlpatterns` list routes URLs to views. For more information please see:
        https://docs.djangoproject.com/en/1.10/topics/http/urls/
    Examples:
    Function views
        1. Add an import:  from my_app import views
        2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
    Class-based views
        1. Add an import:  from other_app.views import Home
        2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
    Including another URLconf
        1. Import the include() function: from django.conf.urls import url, include
        2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))

    import app.views import view_name

    url(

    url(r'^index/$', view_name, name='view_name'),

    )

     
     
  • 相关阅读:
    PHP保留小数的相关方法
    ASP.NET Core MVC 之过滤器(Filter)
    ASP.NET Core MVC 之控制器(Controller)
    ASP.NET Core MVC 之视图组件(View Component)
    ASP.NET Core MVC 之局部视图(Partial Views)
    标签助手(TagHelper)
    ASP.NET Core MVC 之布局(Layout)
    ASP.NET Core MVC 之视图(Views)
    ASP.NET Core MVC 之模型(Model)
    九卷读书:淘宝从小到大的发展 -重读《淘宝技术这十年》
  • 原文地址:https://www.cnblogs.com/honglingjin/p/6671327.html
Copyright © 2011-2022 走看看