eli
eli

Reputation: 5137

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.

Upvotes: 0

Views: 1361

Answers (1)

manji
manji

Reputation: 47978

missing () in if form.is_valid => if form.is_valid()

Upvotes: 3

Related Questions