Django- how to validate a single input field inside a multi-format form

I have a form with several input fields, but I want to use only one input from the form. What is the correct way to validate a field and clear data for one field?

thank!

+3
source share
1 answer

The correct way, probably, is to add it to your form;)

But ... you can do it like this:

form = SomeForm(request.POST)
field = form.fields['your_field']
data = field.widget.value_from_datadict(form.data, form.files, form.add_prefix('your_field'))
cleaned_data = field.clean(data)
+3
source

Source: https://habr.com/ru/post/1775034/


All Articles