Delirium tremens Delirium tremens - 10 days ago 6
Python Question

No module named 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.

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)),
)


I changed
include('mysite.polls.urls')),
to
include(mysite.polls.urls)),
, but it still didn't work.

How to solve this problem?

UPDATE 1: The full error message is at http://dpaste.com/166201/

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'),
)


UPDATE 3: the really full error message splitted in screenshots is at

http://i.imagehost.org/0191/python_1.png

http://i.imagehost.org/0426/python_2.png

http://g.imagehost.org/0191/python_3.png

http://g.imagehost.org/0413/python_4.png

http://i.imagehost.org/0370/python_5.png

http://i.imagehost.org/0317/python_6.png

UPDATE 4: the whole project is at

http://www.mediafire.com/?t1jvomjgjz1

Answer

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:

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:

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'),
)

Visit http://127.0.0.1:8000/polls/ - I received a TemplateDoesNotExist exception because the template file is missing.

I'm afraid my answer might be to reboot and try it again. ;)

Comments