It might sound like a trivial question, but this is quite a battle to me.
For a form, and hit submit, should one uses form.cleaned_data
to access the form data, or look up in request.POST
?
The only thing that people usually do with request.POST
is look up the submit button. But if I created a submit button as a widget, I can also look it up in form.cleaned_data.
The thing is, what about other form data? They are lookup-able in request.POST
as well.
Thanks.
While you could access request.POST directly , it is better to access form.cleaned_data. This data has not only been validated but will also be converted in to the relevant Python types for you.
You can do for example:
class YourForm(forms.Form):
test = forms.CharField(label='A test label', widget=forms.Textarea(attrs={"placeholder":"Your Placeholder", "rows":6, "cols":45}), max_length=150)
if request.method == "POST":
form = YourForm(request.POST)
if form.is_valid():
cleaned_test = form.cleaned_data["test"]
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