Django code samples involving post data often shows code similar to this:
if request.method == "POST":
post = request.POST.copy()
#do stuff with post data
Is there a reason for copying the post data instead of working with it directly?
Django pass POST data to view The input fields defined inside the form pass the data to the redirected URL. You can define this URL in the urls.py file. In this URLs file, you can define the function created inside the view and access the POST data as explained in the above method. You just have to use the HTTPRequest.
The result of request. method == "POST" is a boolean value - True if the current request from a user was performed using the HTTP "POST" method, of False otherwise (usually that means HTTP "GET", but there are also other methods).
Using Form in a View In Django, the request object passed as parameter to your view has an attribute called "method" where the type of the request is set, and all data passed via POST can be accessed via the request. POST dictionary. The view will display the result of the login form posted through the loggedin.
Django puts data in request. POST when a user submits a form with the attribute method="post" . Line 10: You retrieve the submitted value by accessing the data at the key "follow" , which you defined in your template with the name HTML attribute on your <button> elements.
I think it is because request.POST
itself is defined immutable. If you want a version you can actually change (mutability), you need a copy of the data to work with.
See this link (request.POST is a QueryDict instance).
class QueryDict
QueryDict
instances are immutable, unless you create acopy()
of them. That means you can’t change attributes ofrequest.POST
andrequest.GET
directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With