Django请求方法的最佳实践

3
我正在构建一个REST API,我的视图中的一个方法需要接受以下HTTP方法:
GET
POST
DELETE
PUT

什么是实现这一目标的最佳方法?到目前为止,我想出了以下方法。
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')

谢谢

1个回答

3
考虑使用django-piston。它可以实现你所需的功能(以及更多)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接