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()

    问题重现:

    C:Userswuzhi_000DesktopPythonmyweb>python manage.py runserver
    Performing system checks...
    
    Unhandled exception in thread started by <function wrapper at 0x0000000004B6F128>
    Traceback (most recent call last):
      File "C:Python27libsite-packagesdjangoutilsautoreload.py", line 226, in wrapper
        fn(*args, **kwargs)
      File "C:Python27libsite-packagesdjangocoremanagementcommands
    unserver.py", line 121, in inner_run
        self.check(display_num_errors=True)
      File "C:Python27libsite-packagesdjangocoremanagementase.py", line 385, in check
        include_deployment_checks=include_deployment_checks,
      File "C:Python27libsite-packagesdjangocoremanagementase.py", line 372, in _run_checks
        return checks.run_checks(**kwargs)
      File "C:Python27libsite-packagesdjangocorechecks
    egistry.py", line 81, in run_checks
        new_errors = check(app_configs=app_configs)
      File "C:Python27libsite-packagesdjangocorechecksurls.py", line 14, in check_url_config
        return check_resolver(resolver)
      File "C:Python27libsite-packagesdjangocorechecksurls.py", line 24, in check_resolver
        for pattern in resolver.url_patterns:
      File "C:Python27libsite-packagesdjangoutilsfunctional.py", line 35, in __get__
        res = instance.__dict__[self.name] = self.func(instance)
      File "C:Python27libsite-packagesdjangourls
    esolvers.py", line 310, in url_patterns
        patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
      File "C:Python27libsite-packagesdjangoutilsfunctional.py", line 35, in __get__
        res = instance.__dict__[self.name] = self.func(instance)
      File "C:Python27libsite-packagesdjangourls
    esolvers.py", line 303, in urlconf_module
        return import_module(self.urlconf_name)
      File "C:Python27libimportlib\__init__.py", line 37, in import_module
        __import__(name)
      File "C:Userswuzhi_000DesktopPythonmywebmyweburls.py", line 22, in <module>
        url(r'^index/$', 'blog.views.index'),
      File "C:Python27libsite-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().

    解决方案:

    Django doc:

    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'),

    )

  • 相关阅读:
    海量文档查同或聚类问题 Locality Sensitive Hash 算法
    Python之道 (大道至简)
    Inside C++ object Model构造函数
    Python标准模块logging
    Inside C++ object Model多态(ObjectOriented)
    应用Notepad++的正则表达式完成较复杂替换的一个小例子
    维护FAST可用的一些命令 持续更新
    SharePoint List的List Template ID明细表
    SharePoint 2010 Incoming Email怎么配?
    使用ContentDeploymentJob.AddQuickDeployObject的时候, 请注意第三个参数一定要使用Server Relative URL
  • 原文地址:https://www.cnblogs.com/wuzhiyi/p/6495033.html
Copyright © 2011-2022 走看看