gpt4 book ai didi

django - 类型错误 : view must be a callable or a list/tuple in the case of include()

转载 作者:行者123 更新时间:2023-12-04 01:28:56 25 4
gpt4 key购买 nike

我是 Django 和 python 的新手。在 url 映射到 View 期间,我收到以下错误:
类型错误:在 include() 的情况下, View 必须是可调用的或列表/元组。

网址。 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)

追溯

enter image description here

最佳答案

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

from posts.views import post_home

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

关于django - 类型错误 : view must be a callable or a list/tuple in the case of include(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38394598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com