TypeError:对于include(),视图必须是可调用的或列表/元组

我是django和python的新手。在将URL映射到视图的过程中,我遇到以下错误:TypeError:对于include(),视图必须是可调用的或列表/元组。

。py代码:

from django.conf.urls import url

from django.contrib import admin

urlpatterns = [

url(r'^admin/', admin.site.urls),

url(r'^posts/$', "posts.views.post_home"), #posts is module and post_home

]

# is a function in view.

views.py代码:

from django.shortcuts import render

from django.http import HttpResponse

# Create your views here.

#function based views

def post_home(request):

response = "<h1>Success</h1>"

return HttpResponse(response)

回答:

在1.10中,您不能再将导入路径传递到url(),而需要传递实际的view函数:

from posts.views import post_home

urlpatterns = [

...

url(r'^posts/$', post_home),

]

以上是 TypeError:对于include(),视图必须是可调用的或列表/元组 的全部内容, 来源链接: utcz.com/qa/405301.html

回到顶部