【问题标题】:Attribute error in urls.pyurls.py 中的属性错误
【发布时间】: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吗?

标签: python django


【解决方案1】:

答案确实是我的观点有问题。删除 django 项目并从头开始重建整个教程解决了这个问题。

【讨论】:

    猜你喜欢
    • 2020-08-19
    • 1970-01-01
    • 2014-10-20
    • 2013-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    • 2018-11-04
    相关资源
    最近更新 更多