#673 closed defect (invalid)
Final code example in Tutorial 3 is incorrect
| Reported by: | 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: | no | UI/UX: | no |
Description
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/base.py", line 59, in get_response
callback, param_dict = resolver.resolve(path)
File "/home/korpios/devel/py3p/django/core/urlresolvers.py", line 64, in resolve
sub_match = pattern.resolve(new_path)
File "/home/korpios/devel/py3p/django/core/urlresolvers.py", line 64, in resolve
sub_match = pattern.resolve(new_path)
File "/home/korpios/devel/py3p/django/core/urlresolvers.py", line 38, in resolve
self.func = self.get_callback()
File "/home/korpios/devel/py3p/django/core/urlresolvers.py", 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 by , 20 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
comment:2 by , 20 years ago
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 by , 18 years ago
| Reporter: | changed from to |
|---|
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.