Login

Ignore Csrf Middleware

Author:
coleifer
Posted:
June 17, 2010
Language:
Python
Version:
1.2
Score:
2 (after 2 ratings)

Add to your middleware classes before 'django.middleware.csrf.CsrfViewMiddleware'.

1
2
3
class IgnoreCsrfMiddleware(object):
    def process_request(self, request):
        request.csrf_processing_done = True

More like this

  1. Serializer factory with Django Rest Framework by julio 3 months, 2 weeks ago
  2. Image compression before saving the new model / work with JPG, PNG by Schleidens 4 months ago
  3. Help text hyperlinks by sa2812 5 months ago
  4. Stuff by NixonDash 7 months ago
  5. Add custom fields to the built-in Group model by jmoppel 9 months, 1 week ago

Comments

adonm (on June 20, 2010):

Works great - to clarify you add it like so (in settings.py):

class IgnoreCsrfMiddleware(object):
    def process_request(self, request):
        request.csrf_processing_done = True

MIDDLEWARE_CLASSES = (
    'settings.IgnoreCsrfMiddleware',
    'django.contrib.csrf.middleware.CsrfMiddleware',
    ...
    )

#

meitham (on June 24, 2010):

If you are going to ignore the csrf why adding the middleware in the first place?

#

Please login first before commenting.