a recipe i just added to cookbook. hope it can be a little useful :-)
http://code.djangoproject.com/wiki/CookBookMakeURLConfDRY

Question:
In a url configuration file, we use the first argument to the
patterns() function to specify a prefix to apply to each view function
, avoiding typing that out for each entry in urlpatterns. but in the
practical application, it is quite normal that only part of patterns
have the common prefix. In that case, we cann't use a prefix directly
for example:

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'),
              )

Answer:
All Django URL resolver needs is a urlpatterns variable in the url
configuration, which is a list of pattern objects returned by the
patterns() function. So we can do as the following to make our
configuration DRY:

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'),   
              )


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to