TypeError:在include()。hh的情况下,view必须是可调用的或list / tuple

时间:2017-02-04 16:47:47

标签: python django

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',

我需要解决我的问题

1 个答案:

答案 0 :(得分:1)

从您的视图中导入home函数,并在您的网址格式中使用该函数而不是字符串。

from newhomaa.views import home

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

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