问题描述
我正在关注Django教程,我在第3部分的结尾处,将URLconfs解析为,我得到一个没有模块命名urls错误消息。
I'm following the Django Tutorials, I'm at the end of part 3, at Decoupling the URLconfs, at http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03 and I'm getting a "No module named urls" error message.
当我从django.conf更改时:
When I change:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('mysite.polls.views',
(r'^polls/$', 'index'),
(r'^polls/(?P<poll_id>\d+)/$', 'detail'),
(r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
(r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
(r'^admin/', include(admin.site.urls)),
)
to:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^polls/', include('mysite.polls.urls')),
(r'^admin/', include(admin.site.urls)),
)
我更改了 include('mysite.polls.urls')),
到 include(mysite.polls
I changed include('mysite.polls.urls')),
to include(mysite.polls.urls)),
, but it still didn't work.
如何解决这个问题?
更新1:完整的错误消息位于
UPDATE 1: The full error message is at http://dpaste.com/166201/
更新2:在mysite / polls / urls.py是
UPDATE 2: at mysite/polls/urls.py is
from django.conf.urls.defaults import *
urlpatterns = patterns('mysite.polls.views',
(r'^$', 'index'),
(r'^(?P<poll_id>\d+)/$', 'detail'),
(r'^(?P<poll_id>\d+)/results/$', 'results'),
(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
)
更新3:屏幕截图中真正完整的错误消息是在
UPDATE 3: the really full error message splitted in screenshots is at
更新4:整个项目在
推荐答案
我无法使用您的机器重新生成导入错误项目文件(Windows 7,Django 1.1.1,Python 2.6.4)。一切进口都不错,但是网址没有被正确指定(如教程所示)。修正代码:
I can't re-produce the import error on my machine using your project files (Windows 7, Django 1.1.1, Python 2.6.4). Everything imported fine but the urls were not specified properly (like the tutorial shows). Fixing the code:
/mysite/urls.py:
/mysite/urls.py:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^polls/', include('mysite.polls.urls')),
(r'^admin/', include(admin.site.urls)),
)
/mysite/polls/urls.py:
/mysite/polls/urls.py:
from django.conf.urls.defaults import *
urlpatterns = patterns('mysite.polls.views',
(r'^$', 'index'),
(r'^(?P<poll_id>\d+)/$', 'detail'),
(r'^(?P<poll_id>\d+)/results/$', 'results'),
(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
)
访问 - 我收到一个TemplateDoesNotExist异常,因为缺少模板文件。
Visit http://127.0.0.1:8000/polls/ - I received a TemplateDoesNotExist exception because the template file is missing.
恐怕我的答案可能是重新启动并再次尝试。 ;)
这篇关于没有模块命名urls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!