Opened 12 years ago

Closed 12 years ago

Last modified 10 years ago

#673 closed defect (invalid)

Final code example in Tutorial 3 is incorrect

Reported by: Tom Tobin <korpios@…> Owned by: Jacob
Component: Documentation Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


The final code example in Tutorial 3 incorrectly lists 'myproject.apps.polls.views.polls' as the first argument to patterns, as shown below:

urlpatterns = patterns('myproject.apps.polls.views.polls',
    (r'^$', 'index'),
    (r'^(?P<poll_id>\d+)/$', 'detail'),
    (r'^(?P<poll_id>\d+)/results/$', 'results'),
    (r'^(?P<poll_id>\d+)/vote/$', 'vote'),

As is, this will result in a traceback similar to the following (I use "nwly" for my project directory):

There's been an error:

Traceback (most recent call last):

  File "/home/korpios/devel/py3p/django/core/handlers/", line 59, in get_response
    callback, param_dict = resolver.resolve(path)

  File "/home/korpios/devel/py3p/django/core/", line 64, in resolve
    sub_match = pattern.resolve(new_path)

  File "/home/korpios/devel/py3p/django/core/", line 64, in resolve
    sub_match = pattern.resolve(new_path)

  File "/home/korpios/devel/py3p/django/core/", line 38, in resolve
    self.func = self.get_callback()

  File "/home/korpios/devel/py3p/django/core/", line 46, in get_callback
    raise ViewDoesNotExist, "Could not import %s. Error was: %s" % (mod_name, str(e))

ViewDoesNotExist: Could not import nwly.apps.polls.views.polls.nwly.apps.polls.views.polls. Error was: No module named nwly.apps.polls.views.polls

Solution: Make the first argument a blank string, as shown below:

urlpatterns = patterns('',
    (r'^$', 'index'),
    (r'^(?P<poll_id>\d+)/$', 'detail'),
    (r'^(?P<poll_id>\d+)/results/$', 'results'),
    (r'^(?P<poll_id>\d+)/vote/$', 'vote'),

Change History (3)

comment:1 Changed 12 years ago by Jacob

Resolution: invalid
Status: newclosed

If you renamed your project, you will obviously need to rename the view string in your urlconf. The fact that it works at all with the blank string is pretty surprising, actually; if you had a module on sys.path named "detail" (or whatever) you'd get a very ugly error in your solution.

comment:2 Changed 11 years ago by korpios@…

I believe I was misunderstood; I did rename the view string in my urlconf (just as I replaced "myproject" everywhere else), and apologize if I gave the impression that I was simultaneously attempting to use "nwly" and "myproject".

I do admit that I must have been mistaken somewhere, however, as I cannot reproduce the error, starting the tutorial from scratch, with a pull of the revision I had at the time I made the ticket (976). That said, I'm sorry for the hassle -- but I'm glad it's working now. :-D

comment:3 Changed 10 years ago by korpios

Reporter: changed from korpios@… to Tom Tobin <korpios@…>
Note: See TracTickets for help on using tickets.
Back to Top