[Fixed]-How can I raise an error in my Django form?

1👍

You are doing nothing on if form is invalid. When ValidationError is raised django sets form.errors dict with data about what went wrong during validation. Read more https://docs.djangoproject.com/en/1.10/ref/forms/validation/

def request_email_address(request):
    if request.method == "POST":
        form = RequestEmailAddressForm(request.POST)
        if form.is_valid():  # <- form validation is called on this line
            data = form.cleaned_data
            # do something here
            # do redirect here
            return HttpResponseRedirect('/core/home/')
        else:
            pass   
    else:
        form = RequestEmailAddressForm()
    return render(request, "core/request_email_address.html", { "form": form }) 

Leave a comment