[Django]-Django-uni-form helpers and CSRF tags over POST

3👍

Have you checked the source? It should already be there. The uni_form template tag should include it automatically.

2👍

I’m having the exact same problem with django-uni-form. The csrf token does not show up after the <form> tag if I use:

{% load uni_form_tags %}
{% uni_form form helper %}

or:

{% load uni_form_tags %}
{% with form.helper as helper %}
    {% uni_form form helper%}
{%endwith%}

If I include it manually it works:

<form action='{{ request.path }}' method='POST' class="uniForm">{% csrf_token %}
{{ form|safe }}
</form>

I found a blog post that outlines how to include the csrf token manually:

helper = FormHelper()

csrf_token = Hidden(
                name = 'csrfmiddlewaretoken',
                value = request.META['CSRF_COOKIE'])
helper.add_input(csrf_token)

Not at all pretty but at least it gets the uni-form to work.

👤kchan

1👍

The easiest solution is to install django-uni-form from GitHub until the version on PyPi is updated to 0.8.

pip install https://github.com/pydanny/django-uni-form/tarball/master
👤Dave

1👍

Use the most recent version of django-uni-form. It fixes this and so much more.

Leave a comment