Django

Code

Changeset 2816

Show
Ignore:
Timestamp:
05/02/06 14:22:33 (2 years ago)
Author:
adrian
Message:

Added 'Multiple view prefixes' section to docs/url_dispatch.txt. Thanks, Slowness Chen

Files:

Legend:

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

    r2809 r2816  
    289289.. _Django overview: http://www.djangoproject.com/documentation/overview/ 
    290290 
     291Multiple view prefixes 
     292---------------------- 
     293 
     294In practice, you'll probably end up mixing and matching views to the point 
     295where the views in your ``urlpatterns`` won't have a common prefix. However, 
     296you can still take advantage of the view prefix shortcut to remove duplication. 
     297Just add multiple ``patterns()`` objects together, like this: 
     298 
     299Old:: 
     300 
     301    from django.conf.urls.defaults import * 
     302 
     303    urlpatterns = patterns( '' 
     304        (r'^/?$', 'django.views.generic.date_based.archive_index'), 
     305        (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', 'django.views.generic.date_based.archive_month'), 
     306        (r'^tag/(?P<tag>\w+)/$', 'weblog.views.tag'), 
     307    ) 
     308 
     309New:: 
     310 
     311    from django.conf.urls.defaults import * 
     312 
     313    urlpatterns = patterns('django.views.generic.date_based' 
     314        (r'^/?$', 'archive_index'), 
     315        (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$','archive_month'), 
     316    ) 
     317 
     318    urlpatterns += patterns('weblog.views', 
     319        (r'^tag/(?P<tag>\w+)/$', 'tag'), 
     320    ) 
     321 
    291322Including other URLconfs 
    292323========================