Ticket #15354: 03_add_csrf_ensure_cookie_decorator.diff

File 03_add_csrf_ensure_cookie_decorator.diff, 844 bytes (added by lamby, 4 years ago)
  • django/views/decorators/csrf.py

    Re. http://code.djangoproject.com/ticket/15354
    
    diff --git a/django/views/decorators/csrf.py b/django/views/decorators/csrf.py
    index c9fd82c..6e28808 100644
    a b def csrf_exempt(view_func): 
    5757        return view_func(*args, **kwargs)
    5858    wrapped_view.csrf_exempt = True
    5959    return wraps(view_func, assigned=available_attrs(view_func))(wrapped_view)
     60
     61def csrf_ensure_cookie(view_func):
     62    """
     63    Ensures that the CSRF cookie is sent to the client, regardless of whether
     64    we use it to generate a response.
     65    """
     66    def wrapped_view(request, *args, **kwargs):
     67        request.META["CSRF_COOKIE_USED"] = True
     68        return view_func(request, *args, **kwargs)
     69    return wraps(view_func, assigned=available_attrs(view_func))(wrapped_view)
Back to Top