1 de febrero de 2011

Add CSRF token to all your Django templates in a glimpse.

Recently, in my work(at Machinalis: www.machinalis.com) I had the tough experience of having to upgrade a Django app built with Django 0.96 to Django 1.2.4.

I had to deal with things like oldforms, newforms, ObjectPaginator, changing 'maxlength' to 'max_length' in models fieleds and a long list of etc's.

But it came the time for me to deal with integrating csrf to all the giant bunch of forms there around... And that's not meant to be done by a human being :-P

So, I created a Python script for that. You can get it from my GiHub here.

Appart from that, you'll need to add this 'django.middleware.csrf.CsrfViewMiddleware' to MIDDLEWARE_CLASSES in settings.py and, depending on the nature of your project, making several changes more. I'd suggest taking a look(as I did) at the Django Project Reference on CSRF here.

More scripts I made to help upgrading Django 0.96 to 1.2.4 coming soon!

No hay comentarios: