Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24074 closed New feature (wontfix)

Addition: Url convenience function

Reported by: Martin Owens Owned by: nobody
Component: Core (URLs) Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


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('^$', 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.

Change History (2)

comment:1 by Tim Graham, 10 years ago

Resolution: wontfix
Status: newclosed

You can use include() for this, see the last example in

comment:2 by Martin Owens, 10 years ago

It's a bit of a lisp there with all those brackets, but I guess it's better than RY. Thanks for the quick resolution.

Last edited 10 years ago by Martin Owens (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top