Django - 存储在PUT / DELETE请求中的参数在哪里? [英] Django - Where are the params stored on a PUT/DELETE request?

查看:1021
本文介绍了Django - 存储在PUT / DELETE请求中的参数在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想遵循我的新django项目的RESTful模式,我想知道在进行PUT / DELETE请求时参数的位置。



据我所知,我只看到GET& POST QueryDict在请求中,没有其他。
Django在请求中添加了一个新的PUT或DELETE QueryDict,还是添加参数到GET或POST QueryDict?



感谢您的帮助。

解决方案

我假设你问的是,如果你可以有这样的方法:

  def restaction(request,id):
if request.method ==PUT:
someparam = request.PUT [somekey ]

答案是否定的,你不能。 Django不会为PUT,OPTIONS和DELETE请求构建这样的字典,解释的原因是这里



为了总结一下,REST的概念是,您交换的数据可能比简单的键映射到值更复杂。例如,打印图像,或使用json。一个框架不知道你可能想要发送数据的很多方法,所以它显而易见的事情 - 让我们来处理这一点。另请参阅此问题的答案,其中给出相同的回复。



现在,您在哪里找到数据?那么,根据 docs ,django 1.2功能 request.raw_post_data 。作为一个头脑,它看起来像django 1.3将支持 request.read()即类似文件的语义。


I'd like to follow the RESTful pattern for my new django project, and I'd like to know where the parameters are when a PUT/DELETE request is made.

As far as I know, I only see GET & POST QueryDict in the request, no others. Is Django adding a new PUT or DELETE QueryDict regarding to the request, or does it add the parameters to GET or POST QueryDict ?

Thanks for your help.

解决方案

I assume what you're asking is if you can have a method like this:

def restaction(request, id):
    if request.method == "PUT":
        someparam = request.PUT["somekey"]

The answer is no, you can't. Django doesn't construct such dictionaries for PUT, OPTIONS and DELETE requests, the reasoning being explained here.

To summarise it for you, the concept of REST is that the data you exchange can be much more complicated than a simple map of keys to values. For example, PUTting an image, or using json. A framework can't know the many ways you might want to send data, so it does the obvious thing - let's you handle that bit. See also the answer to this question where the same response is given.

Now, where do you find the data? Well, according to the docs, django 1.2 features request.raw_post_data. As a heads up, it looks like django 1.3 will support request.read() i.e. file-like semantics.

这篇关于Django - 存储在PUT / DELETE请求中的参数在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆