简体   繁体   English

在Django表单上绑定不同的表单是什么?

[英]Different form bound on a Django Form What does it?

I'm working on a Project where some old code is and I found a part where I'm not really know what it does. 我正在开发一个项目,其中有一些旧代码,我发现了一个我不知道它的作用的部分。

Here 这里

form = UserForm(request.REQUEST)

What I normally do is 我通常做的是

form = UserForm(request.POST)

What is the difference between this both snippets. 这两个片段之间有什么区别。 What does request.REQUEST in the form? 表单中的request.REQUEST是什么?

Thanks 谢谢

It gives you either request.POST or request.GET , but not recommended to use. 它为您提供request.POSTrequest.GET ,但不建议使用。

From HttpRequest reference 来自HttpRequest参考

HttpRequest.REQUEST HttpRequest.REQUEST

For convenience, a dictionary-like object that searches POST first, then GET. 为方便起见,首先搜索POST的字典对象然后GET。 Inspired by PHP's $_REQUEST. 灵感来自PHP的$ _REQUEST。

For example, if GET = {"name": "john"} and POST = {"age": '34'}, REQUEST["name"] would be "john", and REQUEST["age"] would be "34". 例如,如果GET = {“name”:“john”}和POST = {“age”:'34'},则REQUEST [“name”]将为“john”,REQUEST [“age”]将为“ 34" 。

It's strongly suggested that you use GET and POST instead of REQUEST, because the former are more explicit. 强烈建议您使用GET和POST而不是REQUEST,因为前者更明确。

You could have looked up the documentation for request.REQUEST : 您可以查找文档以获取request.REQUEST

For convenience, a dictionary-like object that searches POST first, then GET. 为方便起见,首先搜索POST的字典对象然后GET。

Perhaps the authors of this code did not know if the form would be submitted via POST or GET, so used REQUEST to make sure they caught both. 也许这段代码的作者不知道表单是通过POST还是GET提交的,所以使用REQUEST来确保它们同时捕获。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM