Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best practice for django request.method methods

I'm building a REST api and one of the methods from my view needs to accept the following http methods

GET
POST
DELETE
PUT

What is the best practice to achieve this ?

So far I came up with the following

with_id_storage = { 
'GET'   : _with_id_get,
'POST'  : _with_id_post,
'PUT'   : _with_id_put,
'DELETE': _with_id_delete,
}

def with_id(request, id):

try:
    log.info('calling %s' % request.method)
    return with_id_storage[request.method](request, test_id)
except KeyError:
    return HttpResponse('Not ready yet')

thanks

like image 473
silviud Avatar asked Jun 25 '26 14:06

silviud


1 Answers

Consider using django-piston. It does what you're asking for (and much more).

like image 168
Sam Dolan Avatar answered Jun 28 '26 04:06

Sam Dolan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!