我是 django 和 python 的新手。在 url 映射到视图期间,我收到以下错误:TypeError: view must be a callable or a list/tuple in case of include()。
网址。代码:-
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)
追溯
原文由 M Pabari 发布,翻译遵循 CC BY-SA 4.0 许可协议
在 1.10 中,您不能再将导入路径传递给
url()
,您需要传递实际的视图函数: