I have a contact form through which users would be able to contact me. I am using django with ajax, and it works fine if there\'s no error. I would like to show
While you could return all json back and add the errors to the fields, another approach would be to render a partial template of just the form and return the html back to the browser. You would then just replace the form with the returned form.
I'm not saying this is the best thing to do, but it is one approach.
For example, you have /form.html and you include it on the page
{% include 'form.html' %}
then in your form_invalid method, return the rendered html string
return render(self.request, 'form.html', {'form' : form}, status=500)
then in your JS error method, replace the form on the page with the html returned from the server.