request.GET vs request.POST/Redirect/GET in django

 ̄綄美尐妖づ 提交于 2020-02-05 08:16:20

问题


In dealing with forms with multiple input parameters and pagination, where user can choose any number of parameters (like a search form) which approach is better and why? receiving data straight from request.GET in one view or implementing a Post/Redirect/Get (2 views).

using Post/Redirect/Get, one can easily sanitize data using ModelForms builtin methods:

if request.method == 'POST': 
    form = MySearchForm(request.POST)
    if form.is_valid():
        cd = form.cleaned_data
        #do stuff with cd

How would you sanitize data using request.GET?

Why would you want to use request.GET instead of POST/Redirect/GET in such circumstances?


回答1:


That depends on what your form does. If you're creating/modifying data, use POST. Otherwise, use GET (see http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods).

You can still use form.cleaned_data with GET, you just have to pass request.GET to the form.



来源:https://stackoverflow.com/questions/28939537/request-get-vs-request-post-redirect-get-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!