Tuesday, December 29, 2015

Re: Display the form errors in the django template with ajax post

I do it like this

create a form template (for abbreviation I will use {{form}}

form_template.html
{{form}}

in include form_template.html public_contact.html
<html>
....
{% include 'form_template.html' %}
</html>
 
and in the ajax response

from django.template.loader import render_to_string

else:
            data = {
                'result': 'error',
                'message': 'Form invalid',
                'form': render_to_string('form_template.html', {'form': form})
            }
            return JsonResponse(data)


I hope this will help you.
--
"La utopía sirve para caminar" Fernando Birri


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAG%2B5VyMfn_umrXFOJk%2Bhf4Ga0xU4uY0vJbp_--d48X93U-PjBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment