【发布时间】:2016-10-19 20:13:59
【问题描述】:
我正在做 django 教程,所以我实际上是在剪切和粘贴代码。我在第 1 步不断收到此错误
from django.conf.urls import url
from django.conf.urls import include
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
我收到这个错误
*/django/theSite/polls/urls.py", line 8, in <module>
url(r'^$', views.index, name='index'),
AttributeError: 'module' object has no attribute 'index'
编辑: 我的视图模块是这个
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
我看不到我错过了什么你有什么建议吗?谢谢!
【问题讨论】:
-
显然
views模块没有定义index名称。 -
我添加了我的views.py,我认为它有一个索引
-
显示您的 views.py 文件:那里有一个错误。还要仔细检查两个文件是否在同一个 (polls/) 子目录中。
-
哎呀,谢谢大家,这是我的 views.py,它们都在 /polls 目录中
-
那个目录里还有
__init__.py吗?