1👍
✅
Yes, you can control these attributes at the time of initialization in the form’s __init__
from django import forms
class PersonForm(forms.Form):
some_field=forms.CharField(max_length=20)
def __init__(self, *args,**kwargs):
required = kwargs.get('required', True)
super(PersonForm,self).__init__(*args,**kwargs)
self.fields['some_field'].required = required
and in template_instance
template_instance = PersonForm(required=False)
You can leave normal_instance = PersonForm()
alone, as it is set to required=True
by default
Source:stackexchange.com