【发布时间】:2015-10-17 02:06:03
【问题描述】:
我不明白为什么这条线会失败:from library import views
from django.conf.urls import include, url
from library import views
urlpatterns = [
url(r'^$', IndexView.as_view()),
]
但这不是:从 library.views 导入 IndexView
from django.conf.urls import include, url
from library.views import IndexView
urlpatterns = [
url(r'^$', IndexView.as_view()),
]
文件views.py
from django.shortcuts import render
from django.views.generic import TemplateView
class IndexView(TemplateView):
template_name = "index.html"
【问题讨论】:
-
在你的第一个例子中不应该是
views.IndexView.as_view()吗? -
错误的全文是什么?
-
@alecxe 是的,你是对的
-
@FranciscoGarcía 阅读完整的错误消息仔细会告诉你错误在哪一行,以及确切的错误是什么。
from library import views行没有失败,是urlpattern[0]的定义失败了。
标签: python django django-views django-urls