简体   繁体   中英

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?

Thanks

It gives you either request.POST or request.GET , but not recommended to use.

From HttpRequest reference

HttpRequest.REQUEST

For convenience, a dictionary-like object that searches POST first, then GET. Inspired by PHP's $_REQUEST.

For example, if GET = {"name": "john"} and POST = {"age": '34'}, REQUEST["name"] would be "john", and REQUEST["age"] would be "34".

It's strongly suggested that you use GET and POST instead of REQUEST, because the former are more explicit.

You could have looked up the documentation for request.REQUEST :

For convenience, a dictionary-like object that searches POST first, then 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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