[Django]-Could not be changed because the data didn't validate. (Django)

4πŸ‘

If form is not getting saved when you perform a check of form.is_valid() means the form was invalid. In such cases, we should display the errors found by the form for every field. For that to happen, first you should pass form data to templates, if form is invalid.

#views.py
def orcamento(request):
    form = OrcamentoForm(request.POST or None, request.FILES or None)
    if request.method == 'POST':
        if form.is_valid():
            form.save()
            return render_to_response("webSite/teste.html", context_instance = RequestContext(request))
    #Following will run in all cases except when form was valid
    return render_to_response("webSite/orcamento.html", {"form": form }, context_instance=RequestContext(request))

You can display all the errors thrown by the form or field-wise errors in your template. See the django documentation detailed understanding.

πŸ‘€Sudipta

0πŸ‘

The same error occurred when I mistyped
.is_valid() as .is_valied().
You might wanna check whether it’s the case.

πŸ‘€user8491363

0πŸ‘

This error can also occur if you never included the () in .is_valid(). Having the validity checker as .is_valid: also raises the same error.

πŸ‘€Jaymoh

0πŸ‘

This error happened to me but I solved by adding parentheses to is_valid and it became is_valid() and the error went and never come back

πŸ‘€Kawuma Julius

Leave a comment