Opened 12 years ago

Closed 12 years ago

#19110 closed Uncategorized (wontfix)

Tutorial Part 3 suggestion

Reported by: pldiver@… Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

In the Tutorial, part 3 when describing the url patterns and conf stuff, for the polls.views.detail ....

This is worth a review. When somebody requests a page from your Web site -- say, "/polls/23/", Django will load this Python module, because it's pointed to by the ROOT_URLCONF setting. It finds the variable named urlpatterns and traverses the regular expressions in order. When it finds a regular expression that matches -- r'polls/(?P<poll_id>\d+)/$' -- it loads the function detail() from polls/views.py. Finally, it calls that detail() function like so:

detail(request=<HttpRequest object>, poll_id=23')

The poll_id='23' part comes from (?P<poll_id>\d+). Using parentheses around a pattern "captures" the text matched by that pattern and sends it as an argument to the view function; the ?P<poll_id> defines the name that will be used to identify the matched pattern; and \d+ is a regular expression to match a sequence of digits (i.e., a number).

I suggest you change the poll_id to 1, 2, or 3 as this is what a user has setup in the tutorial previously. poll_id = '23' will bring up the 404 code.

Not a big deal, but when just starting out, it is nice to see things work.

Patrick

Change History (1)

comment:1 by Tim Graham, 12 years ago

Resolution: wontfix
Status: newclosed

Thanks for the suggestion. There's actually an open ticket (#18715) to refactor tutorial 3 which will address this.

Note: See TracTickets for help on using tickets.
Back to Top