类型错误django包括url ...不应该是django1.11 python2.7的东西

时间:2017-08-20 19:43:07

标签: python django

我在我的主网址文件中使用djangos include功能,来自我的应用网址文件。

main urls.py

from django.conf.urls import include, url
from django.contrib import admin


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^posts/', include('posts.urls')),
]

posts.urls.py

   from django.conf.urls import url

from . import views #relative import to post views


urlpatterns = [
    url(r'$',"views.posts_list" ), #list all posts
    url(r'create/$',"views.posts_create" ),
    url(r'detail/$',"views.posts_detail" ),
    url(r'update/$',"views.posts_update" ),
    url(r'delete/$',"views.posts_delete" ),
]

这是错误:

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

我看过这个问题的文档: https://docs.djangoproject.com/en/1.11/ref/urls/#include

和源代码:

https://docs.djangoproject.com/en/1.11/_modules/django/conf/urls/#include

我不知道我做错了什么。

请帮忙。拥抱亲吻和高五岁

1 个答案:

答案 0 :(得分:2)

Django 1.10+不再允许您在网址格式中将视图指定为字符串(例如gh-ost)。

所以你应该像这样配置帖子'myapp.views.index'

urls.py

from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.posts_list, name='list'), url(r'^create/$', views.posts_create, name='create'), url(r'^detail/$', views.posts_detail, name='detail'), url(r'^update/$', views.posts_update, name='update'), url(r'^delete/$', views.posts_delete, name='delete'), ] 添加到您的网址也是一种很好的做法。