Search code examples
pythondjangotastypie

Tastypie: Directing overridden urls depending on request method


I'm working with one URL in question, let's call it /user/{id}/buckets/

I'd like a GET on /user/{id}/buckets/ to redirect to dispatch_list but a POST to redirect to my own view (process_buckets) for processing.

I understand that urlconfs don't support any way to check for the request method, so how should I go about this?


Solution

  • You can simply overwrite a resource's dispatch method to do whatever you want

    class FooResource(ModelResource):
        class Meta:
            # The usual stuff
    
        def dispatch(self, request_type, request, **kwargs):
            # Do whatever