Some of the URLs in my django application are addressable by both POST
and GET requests. This results in the code like this:

urls.py:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^myapp/myresource/$', 'myproj.myapp.myresource'),
    ....

views.py:
...
def myresource(request):
    if request.META['REQUEST_METHOD'] == 'GET':
        return get_myresource(request)
    elif request.META['REQUEST_METHOD'] == 'POST':
        return post_myresource(request)

def get_myresource(request):
...
def post_myresource(request):
...


Being new to django, I'm wondering if this kind of approach is what
people are generally using? It would seem it could lead to a non-DRY
repetitive code.

What is the best way to dispatch to a method based on both HTTP method
*and* a URL? If such method isn't available within the framework, was
it already considered adding an HTTP method to the url patterns data
structure?

Thanks,
Alexis Smirnov
http://del.icio.us/alexissmirnov/django


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" 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-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to