Python 属性错误:';模块';对象没有属性';指数';

Python 属性错误:';模块';对象没有属性';指数';,python,django,Python,Django,我目前正在阅读Django文档网站上提供的官方教程,遇到了AttributeError。以下是我正在使用的代码: “polls”是我的应用程序的名称 views.py from django.http import HttpResponse def index(request): return HttpResponse("Hello, world. You're at the poll index.") \轮询\url.py from django.conf.urls import

我目前正在阅读Django文档网站上提供的官方教程,遇到了AttributeError。以下是我正在使用的代码:

“polls”是我的应用程序的名称

views.py

from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello, world. You're at the poll index.")
\轮询\url.py

from django.conf.urls import patterns, url

from polls import views

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

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'mysite.views.home', name='home'),
    url(r'^blog/', include('Blog.urls')),
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', include(admin.site.urls)),
)
错误:

AttributeError at /polls

'module' object has no attribute 'index'

Request Method:     GET
Request URL:    http://localhost:8000/polls
Django Version:     1.6.5
Exception Type:     AttributeError
Exception Value:    

'module' object has no attribute 'index'

Exception Location:     C:\Users\manoj\Desktop\Django\mysite\polls\urls.py in <module>, line 6
Python Executable:  F:\Python 2.7\python.exe
Python Version:     2.7.5
Python Path:    

['C:\\Users\\manoj\\Desktop\\Django\\mysite',
 'F:\\Python 2.7\\lib\\site-packages\\pip-1.4.1-py2.7.egg',
 'C:\\Windows\\system32\\python27.zip',
 'F:\\Python 2.7\\DLLs',
 'F:\\Python 2.7\\lib',
 'F:\\Python 2.7\\lib\\plat-win',
 'F:\\Python 2.7\\lib\\lib-tk',
 'F:\\Python 2.7',
 'F:\\Python 2.7\\lib\\site-packages']

Server time:    Thu, 26 Jun 2014 04:44:51 +0530

但是,现在我得到一个NameError:

Exception Type:     NameError
Exception Value:    

name 'views' is not defined
在my/polls/url.py源代码的第6行中:

from django.conf.urls import patterns, url

from polls.views import index

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

views.py
应该在
polls/views.py

from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello, world. You're at the poll index.")

可能与包名称存在冲突。只需尝试将轮询导入视图中的
更改为轮询中的
。视图导入索引中的
,现在我遇到一个名称错误。我已经编辑了我在上面的原始帖子,以包含我遇到的错误的详细信息。
from django.conf.urls import patterns, url

from polls.views import index

urlpatterns = patterns('',
    url(r'^$', views.index, name='index')
)
from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello, world. You're at the poll index.")