20Jan

Using django_uni_form and CSRF

Posted by Elf Sternberg as django, programming

The last update I have to django_uni_form, a rather amazing form layout handler for Django, does not understand what to do with the CSRF token. So in case you’re wondering, after you’ve created your form, you do the following in your view:

        form = FilmForm(initial = {'title': 'History is ...'})
        form.helper.add_input(Hidden(name = 'csrfmiddlewaretoken',
                                     value = request.META['CSRF_COOKIE']))

It’s unfortunate that you have to do it in the view, but it’s the only way to have access to the request.META object, which is where the current CSRF token is stored.

Comment Form

Subscribe to Feed

Categories

Calendar

January 2011
M T W T F S S
« Dec   Feb »
 12
3456789
10111213141516
17181920212223
24252627282930
31