> What is the best way to dispatch to a method based on both HTTP method *and*
> a URL?
Basically you've found it, and it is a clean way to code. However you
have to consider calling get_myresource() from post_myresource(), as
you would probably do if the POST has errors. Typically manipulators
are used to initialize variables in the GET function, but if called
from the post function you would NOT want to re-initialize the vars.
What you could do instead is simply add an optional parameter to the
GET function so you can pass in the already-initialized variables as
needed:
def get_myresource(request, param_dict=None):
if not param_dict:
# initialize from manipulator
display
def post_myresource(request):
You could also very easily make the myresource() method generic, and
take an argument from URLConf. Something like:
def dispatchview(request, viewname):
method_type = request.POST and 'post' or 'get'
method = getattr(views, '%s_%s' % (method_type, viewname))
return method(request)
-rob
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---