zoukankan      html  css  js  c++  java
  • django报错解决:view must be a callable or a list/tuple in the case of include().

    django版本:1.11.15

    django应用,修改urls.py后,访问报错:
    TypeError at /
    view must be a callable or a list/tuple in the case of include().

    修改后的urls.py文件:
    from django.conf.urls import url
    from django.contrib import admin

    urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', 'hello.views.home',name='home'),
    url(r'^hello/$', 'hello.views.hello',name='hello'),
    ]

    这是因为:从1.10后django后patterns被移除了,已经没有这个模块了。

    修改为:
    from django.conf.urls import url
    from django.contrib import admin
    from hello import views

    urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.home,name='home'),
    url(r'^hello/$', views.hello,name='hello'),
    ]

    重启uwsgi后,访问正常。

    其实urls.py里已经注释说明了:

    """hello URL Configuration

    The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/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'))
    """

    django版本差异造成的,o(╥﹏╥)o

    done!

  • 相关阅读:
    git创建一个空的版本库
    程序后台服务启动,MongoDB未启动(启动较慢)/(关机重启情况下)。
    启动客户端后台服务
    客户端后台服务(已注册机器)RabbitMQ未消费的情况
    MongoDB数据重复解决方案
    github中新建一个branch(分支)
    MES-后台服务卸载
    linux 第八章 高级键盘
    socketserver
    jmeter发送邮件的模板
  • 原文地址:https://www.cnblogs.com/zqifa/p/django-urls-1.html
Copyright © 2011-2022 走看看