Validation of manually created form - forms.Form needed / recommended?

Hi all,

in my template I have a manually created form (no forms.Form). This is populated with three fields that are of type “select” (video file, subtitle file, position of subtitle). When the view is called, the content of the directories is retrieved and passed to the template.

I didn’t understand, if I can use a custom form (inherited from forms.Form) to populate the content of the “select” options on the fly and then validate them. This time I search files in directories, but I’d also like to populate fields on the fly with content retrieved from the internet.

Since I manually populate the content of the “select” options, should I validate the fields? Is it recommended? If I can use a custom form (inherited from forms.Form) then I’d use "form.cleaned_data without having to manually validate the fields.

What is the best practice in this case?

Thanks in advance,


Yes, you want to use Django forms. There’s a lot of validation that it performs for you - and that’s before you even need to handle what Django doesn’t.

Yes, you can create any arbitrary set of options for your select widgets. Exactly how best do that is affected greatly by the specifics of what the options are you’re looking to present.

Keep in mind that validating a selection means you need to have the same options available after the form is posted as are available when it’s posted.

Review the following docs to become familiar with your options here:

Thank you, I’ve read the documentation that you suggested and I used Django Forms.
For the three fields I’ve used the ChoiceField with the default widget Select.

To be able to filter the choices dynamically in the page I’ve used “select2”.