1👍
You should override the dispatch
method from the Resource, and there create each one of your functions. If you want to do some simple logic, you would place your code after the call to the Resource original dispatch
. The code would look something like this:
def dispatch(self, request_type, request, **kwargs):
response = super(Resource, self).dispatch(request_type, request, **kwargs)
# Pass any parameters that you require to the functions
if request.method == 'GET':
custom_get()
if request.method == 'POST':
custom_post()
if request.method == 'PUT':
custom_put()
if request.method == 'DELETE':
custom_delete()
return response
In general terms it should be enough for your purpose, except if you want to do some more complex stuff with the response.
Source:stackexchange.com