#24074: Addition: Url convenience function
-----------------------------+--------------------
     Reporter:  doctormo     |      Owner:  nobody
         Type:  New feature  |     Status:  new
    Component:  Core (URLs)  |    Version:  1.6
     Severity:  Normal       |   Keywords:
 Triage Stage:  Unreviewed   |  Has patch:  1
Easy pickings:  1            |      UI/UX:  0
-----------------------------+--------------------
 We're using a convenience function in our website urls and I want to
 propose it's inclusion into django upstream. I'm sounding out developers
 feelings on such an addition before I generate a patch and connected
 documentation.

 Code (for django.conf.urls):
 {{{
 def url_tree(regex, *urls):
     return url(regex, include(patterns('', *urls)))
 }}}

 This function cleans up url definitions that contain multiple layers. For
 example if you had a urls file containing:
 {{{
 urlpatterns = patterns('',
   url(r'^$', MyListView.as_view()),
   url(r'^(?P<pk>\d+)/$', MyItemView.as_view()),
   url(r'^(?P<pk>\d+)/delete/$', MyDeleteView.as_view()),
   url(r'^(?P<pk>\d+)/post/$', MyPostView.as_view()),
 )
 }}}

 And DRY it into:
 {{{
 urlpatterns = patterns('',
   url(r'^$', MyListView.as_view()),
   url_tree(r'^(?P<pk>\d+)/',
     url('^$', MyItemView.as_view()),
     url(r'^delete/$', MyDeleteView.as_view()),
     url(r'^post/$', MyPostView.as_view()),
   ),
 )
 }}}
 This function gets very useful with tens of possible functions and long
 urls. So. Does this make sense as an addition to django? Is the
 functionality already there an I've missed it? Let me know.

--
Ticket URL: <https://code.djangoproject.com/ticket/24074>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.14b4aed37394f2c24527d17d6ff92010%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to