Django ModelForm validation and error messages
Sorry if this is a basic question: I am having trouble doing form validation with ModelForms in Django.
The pattern I'm using is
def View(request):
if request.method == 'POST':
form = AddPageForm(request.POST)
if form.is_valid:
instance = form.save()
...
else:
HttpResponse("Error")
This works fine if the form validates (the if
... branch is followed.) When the form doesn't validate, I get a standard Django form validation error page; the else
... branch is ignored.开发者_开发技巧
Obviously, there must be something wrong/missing but I can't work out what from the official Django documentation. Any guidance would be appreciated.
missing () in if form.is_valid
=> if form.is_valid()
精彩评论