-
Notifications
You must be signed in to change notification settings - Fork 31
/
csrf.py
42 lines (29 loc) · 1.13 KB
/
csrf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
csrf related views
~~~~~~~~~~~~~~~~~~
debug_csrf_failure()
~~~~~~~~~~~~~~~~~~~~
Display the normal debug page and not the minimal csrf debug page.
usage: Add this to your settings:
-----------------------------------------------------------------------
CSRF_FAILURE_VIEW='django_tools.views.csrf.debug_csrf_failure'
-----------------------------------------------------------------------
:copyleft: 2012 by the django-tools team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""
from django.conf import settings
from django.views.csrf import csrf_failure
class CsrfFailure(Exception):
pass
def debug_csrf_failure(request, reason=""):
"""
raised own CsrfFailure() exception to get the normal debug page on
Csrf failures.
See also:
https://docs.djangoproject.com/en/1.3/ref/contrib/csrf/#rejected-requests
More Info: See DocString above.
"""
if not settings.DEBUG:
# Use original HttpResponseForbidden:
return csrf_failure(request, reason)
raise CsrfFailure(f"csrf failure debug: {reason!r}")