Anonymous user
Boston Python Workshop/Saturday/Web app project: Difference between revisions
Boston Python Workshop/Saturday/Web app project (view source)
Revision as of 20:31, 5 March 2011
, 13 years ago→Adding URLs to urls.py
Line 471:
Time for an example. Edit mysite/urls.py so it looks like this:
<pre>
from django.conf.urls.defaults import *
Line 479 ⟶ 480:
(r'^polls/(\d+)/vote/$', 'polls.views.vote'),
)
</pre>
This is worth a review. When somebody requests a page from your Web site -- say, "/polls/23/", Django will load the ''urls.py'' 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/(\d+)/$' -- it loads the function detail() from polls/views.py. Finally, it calls that detail() function like so:
|