How can you dispatch on request method in Django URLpatterns?
Posted
by rcampbell
on Stack Overflow
See other posts from Stack Overflow
or by rcampbell
Published on 2010-06-03T08:30:59Z
Indexed on
2010/06/03
8:34 UTC
Read the original article
Hit count: 270
It's clear how to create a URLPattern which dispatches from a URL regex:
(r'^books/$', books),
where books can further dispatch on request method:
def books(request):
if request.method == 'POST':
...
else
...
I'd like to know if there is an idiomatic way to include the request method inside the URLPattern, keeping all dispatch/route information in a single location, such as:
(r'^books/$', GET, retrieve-book),
(r'^books/$', POST, update-books),
(r'^books/$', PUT, create-books),
© Stack Overflow or respective owner