#15645: HTTP methods in urls.py
-------------------------------------+-------------------------------------
Reporter: haras | Owner: nobody
Status: new | Milestone:
Component: HTTP | Version:
handling | Keywords: http urls
Resolution: | Has patch: 0
Triage Stage: Design | Needs tests: 0
decision needed |
Needs documentation: 0 |
Patch needs improvement: 0 |
-------------------------------------+-------------------------------------
Comment (by haras):
I know that this maybe encumber an urlpatterns but consider this:
{{{
from django.conf.urls.defaults import http
from django.conf.urls.defaults import url
from django.conf.urls.defaults import patterns
from django.conf.urls.defaults import include
from django.contrib import admin
urlpatterns = patterns('myapp',
http.ajax (r'/user/(?P<username>\d+)$', 'views.view1'),
http.post (r'/user/(?P<username>\d+)$', 'views.view2'),
http.get (r'/user/(?P<username>\d+)$', 'views.view2'),
http.delete (r'/user/(?P<username>\d+)$', 'views.delete'),
# an url function will do the old way
url (r'^', include(admin.site.urls)),
)
}}}
or equivalent
{{{
from django.conf.urls.defaults import http
from django.conf.urls.defaults import url
from django.conf.urls.defaults import patterns
from django.conf.urls.defaults import include
from django.contrib import admin
urlpatterns = patterns('myapp',
http ('POST', r'/user/(?P<username>\d+)$', 'views.view1'),
http ('GET', r'/user/(?P<username>\d+)$', 'views.view2'),
http ('DELETE', r'/user/(?P<username>\d+)$', 'views.delete'),
# an url function will do the old way
url (r'^', include(admin.site.urls)),
)
}}}
therefore maybe a request not http module name is better to consider
IMHO:
first (http.ajax, http.get, http.post...) solution is the most clear and
the best fit to the explicit python policy
it is simple and I think it would boost urls dispatcher performance
when it may easy and fast filter lot of regexp pattern, hence there is no
need to lookup in POST list regexps when we have a GET request
maybe distinguishing of ajax methods isn't a bad idea too:
{{{
from django.conf.urls.defaults import ajax
from django.conf.urls.defaults import patterns
urlpatterns = patterns('myapp',
ajax.post (r'/user/(?P<username>\d+)$', 'views.view2'),
ajax.get (r'/user/(?P<username>\d+)$', 'views.view2'),
ajax.delete (r'/user/(?P<username>\d+)$', 'views.delete'),
)
}}}
It gives a little logic to urls.py but gives a performance, simplicity and
readability in return
this in conclusion would give us:
{{{
from django.conf.urls.defaults import ajax
from django.conf.urls.defaults import http
from django.conf.urls.defaults import url
from django.conf.urls.defaults import patterns
from django.conf.urls.defaults import include
from django.contrib import admin
urlpatterns = patterns('myapp',
ajax.post (r'/user/(?P<username>\d+)$', 'views.viewAjax1'),
ajax.get (r'/user/(?P<username>\d+)$', 'views.viewAjax2'),
ajax.delete (r'/user/(?P<username>\d+)$', 'views.delete'),
ajax.all (r'/user/(?P<username>\d+)$', 'views.delete'), #all type of
methods
ajax (r'/user/(?P<username>\d+)$', 'views.delete'), #all type of
methods
ajax ('POST', r'/user/(?P<username>\d+)$', 'views.view2'),
ajax ('GET', r'/user/(?P<username>\d+)$', 'views.view2'),
ajax ('DELETE', r'/user/(?P<username>\d+)$', 'views.view2'),
http.post (r'/user/(?P<username>\d+)$', 'views.view2'),
http.get (r'/user/(?P<username>\d+)$', 'views.view2'),
http.delete (r'/user/(?P<username>\d+)$', 'views.delete'),
http (r'/user/(?P<username>\d+)$', 'views.delete'), #all type of methods
http ('POST', r'/user/(?P<username>\d+)$', 'views.view2')
http ('GET', r'/user/(?P<username>\d+)$', 'views.view2')
http ('DELETE', r'/user/(?P<username>\d+)$', 'views.view2')
# an url function will do the old way
url (r'^', include(admin.site.urls)),
)
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/15645#comment:3>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.