It would be nice to have possibility to distinguish a HTTP method in
urls.py. IMHO it would be clearer and more extensible in future for
example:

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

  #or equivalent
  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.all (r'/user/(?P<username>\d+)$', 'views.delete'), #all type of
methods

  #or equivalent
  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)),
)

It gives a little logic to urls.py but gives a performance, simplicity
and readability in return.

I think this is a good way of getting rid of nested ifs in each view:

if request.is_ajax:
  #do stuff
else:
  if request.method == "POST":
     #do something
   else:
     #do else

Hence my true code is almost two indents inside those boilerplate if
structure. Which is always the same... it takes a lot of python beauty
and readibility from code.

IMHO: 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

someone closes a ticket, but take a look and decide,
I consider it as a very good idea
http://code.djangoproject.com/ticket/15645

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to