Django

Code

Changeset 1453

Show
Ignore:
Timestamp:
11/27/05 08:35:18 (3 years ago)
Author:
adrian
Message:

Fixed several bugs in docs/url_dispatch.txt, and made several clarifications

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/url_dispatch.txt

    r1292 r1453  
    5757 
    5858    urlpatterns = patterns('', 
    59         (r'^/articles/2003/$', 'news.views.special_case_2003'), 
    60         (r'^/articles/(?P<year>\d{4})/$', 'news.views.year_archive'), 
    61         (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'news.views.month_archive'), 
    62         (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'news.views.article_detail'), 
     59        (r'^articles/2003/$', 'news.views.special_case_2003'), 
     60        (r'^articles/(?P<year>\d{4})/$', 'news.views.year_archive'), 
     61        (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'news.views.month_archive'), 
     62        (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'news.views.article_detail'), 
    6363    ) 
    6464 
     
    7171      where ``name`` is the name for that value and ``pattern`` is some pattern 
    7272      to match. 
     73 
     74    * There's no need to add a leading slash, because every URL has that. For 
     75      example, it's ``^articles``, not ``^/articles``. 
    7376 
    7477    * The ``"r"`` in front of each regular expression string is optional but 
     
    169172URLconf:: 
    170173 
    171     (r'^/articles/(?P<year>\d{4})/$', 'news.views.year_archive'), 
     174    (r'^articles/(?P<year>\d{4})/$', 'news.views.year_archive'), 
    172175 
    173176...the ``year`` argument to ``news.views.year_archive()`` will be a string, not 
     
    179182    # URLconf 
    180183    urlpatterns = patterns('', 
    181         (r'^/blog/$', 'blog.views.page'), 
    182         (r'^/blog/page(?P<num>\d+)/$', 'blog.views.page'), 
     184        (r'^blog/$', 'blog.views.page'), 
     185        (r'^blog/page(?P<num>\d+)/$', 'blog.views.page'), 
    183186    ) 
    184187 
     
    210213 
    211214    urlpatterns = patterns('', 
    212         (r'^/articles/(?P<year>\d{4})/$', 'myproject.news.views.year_archive'), 
    213         (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'myproject.news.views.month_archive'), 
    214         (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'myproject.news.views.article_detail'), 
     215        (r'^articles/(?P<year>\d{4})/$', 'myproject.news.views.year_archive'), 
     216        (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'myproject.news.views.month_archive'), 
     217        (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'myproject.news.views.article_detail'), 
    215218    ) 
    216219 
     
    225228 
    226229    urlpatterns = patterns('myproject.news.views', 
    227         (r'^/articles/(?P<year>\d{4})/$', 'year_archive'), 
    228         (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'month_archive'), 
    229         (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'article_detail'), 
     230        (r'^articles/(?P<year>\d{4})/$', 'year_archive'), 
     231        (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'month_archive'), 
     232        (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'article_detail'), 
    230233    ) 
    231234 
     
    253256    ) 
    254257 
    255 Note that an included URLconf receives any captured parameters from parent 
    256 URLconfs, so the following example is valid:: 
     258Note that the regular expressions in this example don't have a ``$`` 
     259(end-of-string match character) but do include a trailing slash. Whenever 
     260Django encounters ``include()``, it chops off whatever part of the URL matched 
     261up to that point and sends the remaining string to the included URLconf for 
     262further processing. 
     263 
     264.. _`Django website`: http://www.djangoproject.com/ 
     265 
     266Captured parameters 
     267------------------- 
     268 
     269An included URLconf receives any captured parameters from parent URLconfs, so 
     270the following example is valid:: 
    257271 
    258272    # In settings/urls/main.py 
     
    270284included URLconf, as expected. 
    271285 
    272 .. _`Django website`: http://www.djangoproject.com/ 
    273  
    274286Passing extra options to view functions 
    275287=======================================