【问题标题】:TypeError: view must be a callable or a list/tuple in the case of include().hh [duplicate]TypeError:在 include().hh 的情况下,视图必须是可调用的或列表/元组 [重复]
【发布时间】:2017-06-21 22:13:48
【问题描述】:
TypeError: view must be a callable or a list/tuple in the case of include().

网址

from django.conf.urls import include, url

from django.contrib import admin

urlpatterns = [
url(r'^$',"newhomaa.views.home", name='home'),
url(r'^admin/', include(admin.site.urls)),

观看次数

from django.shortcuts import render
def home(request):
return render(request,"home.html",{})

INSTALLED_APPS
= [

'newhomaa',

我需要解决我的问题

【问题讨论】:

标签: python django


【解决方案1】:

从您的视图中导入 home 函数,并在您的 url 模式中使用它而不是字符串。

from newhomaa.views import home

urlpatterns = [
    url(r'^$', home, name='home'),
    url(r'^admin/', admin.site.urls),
]

请注意,在 Django 1.9+ 中,您不需要将 include()admin.site.urls 一起使用。

【讨论】:

    猜你喜欢
    • 2016-11-18
    • 2017-01-23
    • 2023-03-29
    • 1970-01-01
    • 2018-07-06
    • 2019-12-14
    • 2017-08-14
    • 2019-11-11
    • 1970-01-01
    相关资源
    最近更新 更多