Django

Code

Changeset 236

Show
Ignore:
Timestamp:
07/19/05 20:16:51 (3 years ago)
Author:
adrian
Message:

Fixed typos and tightened up docs/url_dispatch.txt

Files:

Legend:

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

    r70 r236  
    1 ============ 
    2 URL dispatch 
    3 ============ 
     1============== 
     2URL dispatcher 
     3============== 
    44 
    55We're fanatics about good URLs.  No ".php" or ".cgi", and certainly not any of 
    6 that "0,2097,1-1-1928,00" nonsense. Django's URL dispatch lets you design 
     6that "0,2097,1-1-1928,00" nonsense. Django's URL dispatcher lets you design 
    77your URLs to be as pretty as the rest of your application. 
    88 
    9 See `the Django overview`_ for a quick introduction to URL dispatch; this 
    10 document will continue on from there. 
     9See `the Django overview`_ for a quick introduction to URL configurations; this 
     10document will continue from there. 
    1111 
    1212.. _`the Django overview`: http://www.djangoproject.com/documentation/overview/#design-your-urls 
     
    1818 
    1919    from django.conf.urls.defaults import * 
    20      
     20 
    2121    urlpatterns = patterns('', 
    22         (r'^/articles/(?P\d{4})/$',                  'myproject.news.views.articles.year_archive'), 
    23         (r'^/articles/(?P\d{4})/(?P\d{2})/$',        'myproject.news.views.articles.month_archive'), 
    24         (r'^/articles/(?P\d{4})/(?P\d{2})/$',        'myproject.news.views.articles.month_archive'), 
    25         (r'^/articles/(?P\d{4})/(?P\d{2})/(?P\d+)/$', 'myproject.news.views.articles.article_detail'), 
     22        (r'^/articles/(?P<year>\d{4})/$', 'myproject.news.views.articles.year_archive'), 
     23        (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'myproject.news.views.articles.month_archive'), 
     24        (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'myproject.news.views.articles.month_archive'), 
     25        (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'myproject.news.views.articles.article_detail'), 
    2626    ) 
    27      
     27 
    2828You can see that the first argument to ``patterns`` is an empty string in the 
    29 above example, but it's actually very useful.  The first argument will be 
    30 prepended to all the view functions in the urlpatterns list, so the above  
    31 example could be written more concisely as:: 
     29above example, but that argument is actually very useful. The first argument 
     30will be prepended to all the view functions in the urlpatterns list, so the 
     31above example could be written more concisely as:: 
    3232 
    3333    urlpatterns = patterns('myproject.news.views.articles', 
    34         (r'^/articles/(?P\d{4})/$',                  'year_archive'), 
    35         (r'^/articles/(?P\d{4})/(?P\d{2})/$',        'month_archive'), 
    36         (r'^/articles/(?P\d{4})/(?P\d{2})/$',        'month_archive'), 
    37         (r'^/articles/(?P\d{4})/(?P\d{2})/(?P\d+)/$', 'article_detail'), 
     34        (r'^/articles/(?P<year>\d{4})/$', 'year_archive'), 
     35        (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'month_archive'), 
     36        (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'month_archive'), 
     37        (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'article_detail'), 
    3838    ) 
    3939 
    40 Including other URL config
    41 =========================== 
     40Including other URLconf
     41======================== 
    4242 
    43 You can also "include" other URL config modules at any point along the path.  
    44 This is essence "roots" a set of URLs below other ones.  This is most often used 
    45 for a site's "base" URL config; the ``ROOT_URLCONF`` setting points to a urlconf 
    46 module that will be used for the entire site.  This is the URL config for the 
    47 `Django website`_ itself which includes a number of other URL config modules:: 
     43You can also "include" other URL config modules at any point along the path. 
     44This essentially "roots" a set of URLs below other ones.  This is most often 
     45used for a site's "base" URLconfig; the ``ROOT_URLCONF`` setting points to a 
     46urlconf module that will be used for the entire site. Here's the URLconf 
     47for the `Django website`_ itself. It includes a number of other URLconfs:: 
    4848 
    4949    from django.conf.urls.defaults import * 
    50      
     50 
    5151    urlpatterns = patterns('', 
    5252        (r'^weblog/',        include('django_website.apps.blog.urls.blog')), 
     
    5656        (r'',                include('django.conf.urls.flatfiles')), 
    5757    ) 
    58      
     58 
    5959.. _`Django website`: http://www.djangoproject.com/ 
    6060 
     
    6464There are two ways of passing arguments into your view functions: named captures 
    6565from the regex (which you've already seen) and the optional third element 
    66 in url config tuples.  This third element can be a dictionary of extra 
    67 keyword arguments that will be passed to the view function:: 
     66in URLconf tuples. This third element can be a dictionary of extra keyword 
     67arguments that will be passed to the view function:: 
    6868 
    6969    urlpatterns = patterns('myproject.news.views.articles', 
    70         (r'^/articles/(?P\d{4})/$', 'year_archive', {key: value, key2: value 2}), 
     70        (r'^/articles/(?P<year>\d{4})/$', 'year_archive', {key: value, key2: value 2}), 
    7171    ) 
    72  
    73 This is especially useful for `generic view functions`_. 
    74  
    75 .. _`generic view functions`: http://www.djangoproject.com/documentation/generic_views/