Django教程:URL未正确映射

时间:2014-11-28 21:35:46

标签: python django python-2.7

我正处于Django教程的这个阶段:https://docs.djangoproject.com/en/1.7/intro/tutorial03/

我已经按照在我的民意调查app目录中创建urls.py的所有步骤,以及在mysite目录中编辑urls.py。这是我的代码:

#polls\urls.py

from django.conf.urls import patterns, urls
from polls import views

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

#mysite\urls.py

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

urlpatterns = patterns('',
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

当我尝试在浏览器上加载http://localhost:8000/polls/时,最终会发生这种情况,这是我得到的错误:

ImportError at /polls/
cannot import name urls
Request Method: GET
Request URL:    http://localhost:8000/polls/
Django Version: 1.7.1
Exception Type: ImportError
Exception Value:    
cannot import name urls
Exception Location: C:\Users\Paul.Zovighian\desktop\django\mysite\polls\urls.py in <module>, line 1
Python Executable:  C:\Python27\python.exe
Python Version: 2.7.8
Python Path:    
['C:\\Users\\Paul.Zovighian\\desktop\\django\\mysite',
 'C:\\Python27\\lib\\site-packages\\pandas-0.14.1-py2.7-win32.egg',
 'C:\\Python27\\lib\\site-packages\\pytz-2014.7-py2.7.egg',
 'C:\\Windows\\system32\\python27.zip',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win',
 'C:\\Python27\\lib\\lib-tk',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages',
 'C:\\Python27\\lib\\site-packages\\win32',
 'C:\\Python27\\lib\\site-packages\\win32\\lib',
 'C:\\Python27\\lib\\site-packages\\Pythonwin']
Server time:    Fri, 28 Nov 2014 16:29:44 +0000

任何想法男人和女孩?

1 个答案:

答案 0 :(得分:4)

您正在尝试import urls

from django.conf.urls import patterns, urls

将其更改为。

from django.conf.urls import patterns, url

polls\urls.py模块中。