在 Django 中集成 html 模板和 url 时出错

Error while integration a html template and url in django

我正在使用 Django 版本 1.10。

下面是我的urls.py(前端),

from django.conf.urls import include,url
from django.contrib import admin

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

下面是我的urls.py(webApp),

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),

]

下面是我的 views.py,

def home(request):
    return render_to_response('home.html')

这里,frontend是我的项目名,webApp是我的应用名。我在 frontend.

templates 文件夹中有一个 home.html

当我运行,

python manage.py runserver 0.0.0.0:8000

我收到以下错误,

File "/root/frontend/frontend/urls.py", line 22, in <module>
url(r'^home/$', 'frontend.views.home', name='home'),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 85, in url
raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include()

我不知道我做错了什么...有任何指导吗?

urlpatterns 列表中,您没有正确使用函数 url(您传递的是一个字符串作为其第二个参数,但它 - 在本例中 - [..] must be a callable [..]) .

所以...只需将 'frontend.views.home' 更改为 frontend.views.home(即删除单引号),您应该没问题。