Answer the question
In order to leave comments, you need to log in
Why are unbound forms not valid in django?
There is a form with initial values specified in initial:
forms:
class UserEditForm(forms.Form):
sn = forms.CharField(required=True)
ml = forms.EmailField(required=True)
mr = forms.EmailField(required=True)
form = UserEditForm(data=request.POST or None, initial={'sn': user.sn, 'ml': user.ml, 'mr': user.mr})
form.is_valid()
it is always False? Answer the question
In order to leave comments, you need to log in
if you do not pass data to the form or pass None,
then the is_bound flag will be False:
and accordingly the form will always be invalid!
def is_valid(self):
"""
Returns True if the form has no errors. Otherwise, False. If errors are
being ignored, returns False.
"""
return self.is_bound and not self.errors
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question