[Django] #24074: Addition: Url convenience function

4 views
Skip to first unread message

Django

unread,
Jan 3, 2015, 4:16:39 PM1/3/15
to django-...@googlegroups.com
#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.

Django

unread,
Jan 3, 2015, 5:18:17 PM1/3/15
to django-...@googlegroups.com
#24074: Addition: Url convenience function
-----------------------------+--------------------------------------
Reporter: doctormo | Owner: nobody
Type: New feature | Status: closed

Component: Core (URLs) | Version: 1.6
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* needs_better_patch: => 0
* resolution: => wontfix
* needs_tests: => 0
* needs_docs: => 0


Comment:

You can use `include()` for this, see the last example in
https://docs.djangoproject.com/en/dev/topics/http/urls/#including-other-
urlconfs.

--
Ticket URL: <https://code.djangoproject.com/ticket/24074#comment:1>

Django

unread,
Jan 3, 2015, 5:21:42 PM1/3/15
to django-...@googlegroups.com
#24074: Addition: Url convenience function
-----------------------------+--------------------------------------
Reporter: doctormo | Owner: nobody
Type: New feature | Status: closed

Component: Core (URLs) | Version: 1.6
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by doctormo):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/24074#comment:2>

Reply all
Reply to author
Forward
0 new messages