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

In 1.10, you can no longer pass import paths to url(), you need to pass the actual view function:

from posts.views import post_home

urlpatterns = [
    ...
    url(r'^posts/$', post_home),
]


在django 1.10 里面urls.py 新的写法: 
urls.py 文件里添加blog的url:

from django.conf.urls import url
from django.conf.urls import include
from django.contrib import admin
from blog.views import index
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^index/$',index),
]

 

如果使用django1.10以下的版本则写法:

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

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^index/$',"blog.views.index"),
]
 
posted @ 2017-06-18 11:12  xqnq2007  阅读(219)  评论(0编辑  收藏  举报