Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added 'Multiple view prefixes' section to docs/url_dispatch.txt. Than…

…ks, Slowness Chen

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2816 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit aba95b718cff6a4690a9bcadedd2dbff7439c4a2 1 parent cc4196a
@adrianholovaty adrianholovaty authored
Showing with 31 additions and 0 deletions.
  1. +31 −0 docs/url_dispatch.txt
View
31 docs/url_dispatch.txt
@@ -288,6 +288,37 @@ that in automatically.
.. _Django overview: http://www.djangoproject.com/documentation/overview/
+Multiple view prefixes
+----------------------
+
+In practice, you'll probably end up mixing and matching views to the point
+where the views in your ``urlpatterns`` won't have a common prefix. However,
+you can still take advantage of the view prefix shortcut to remove duplication.
+Just add multiple ``patterns()`` objects together, like this:
+
+Old::
+
+ from django.conf.urls.defaults import *
+
+ urlpatterns = patterns( ''
+ (r'^/?$', 'django.views.generic.date_based.archive_index'),
+ (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', 'django.views.generic.date_based.archive_month'),
+ (r'^tag/(?P<tag>\w+)/$', 'weblog.views.tag'),
+ )
+
+New::
+
+ from django.conf.urls.defaults import *
+
+ urlpatterns = patterns('django.views.generic.date_based'
+ (r'^/?$', 'archive_index'),
+ (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$','archive_month'),
+ )
+
+ urlpatterns += patterns('weblog.views',
+ (r'^tag/(?P<tag>\w+)/$', 'tag'),
+ )
+
Including other URLconfs
========================
Please sign in to comment.
Something went wrong with that request. Please try again.