summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2009-10-27 00:36:34 +0000
committerLuke Plant <L.Plant.98@cantab.net>2009-10-27 00:36:34 +0000
commit7230a995ce81a7b8dd093bd03cc5ebd34106ee80 (patch)
tree398b0f0b48eb6d4b2c3b69f0e2d7dc2749ec7a74 /django/core
parent8e70cef9b67433edd70935dcc30c621d1e7fc0a0 (diff)
Moved contrib.csrf.* to core code.
There is stub code for backwards compatiblity with Django 1.1 imports. The documentation has been updated, but has been left in docs/contrib/csrf.txt for now, in order to avoid dead links to documentation on the website. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11661 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
-rw-r--r--django/core/context_processors.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/django/core/context_processors.py b/django/core/context_processors.py
index 0dbd8449b6..b950dba0f6 100644
--- a/django/core/context_processors.py
+++ b/django/core/context_processors.py
@@ -8,6 +8,7 @@ RequestContext.
"""
from django.conf import settings
+from django.middleware.csrf import get_token
from django.utils.functional import lazy, memoize, SimpleLazyObject
def auth(request):
@@ -40,6 +41,24 @@ def auth(request):
'perms': lazy(lambda: PermWrapper(get_user()), PermWrapper)(),
}
+def csrf(request):
+ """
+ Context processor that provides a CSRF token, or the string 'NOTPROVIDED' if
+ it has not been provided by either a view decorator or the middleware
+ """
+ def _get_val():
+ token = get_token(request)
+ if token is None:
+ # In order to be able to provide debugging info in the
+ # case of misconfiguration, we use a sentinel value
+ # instead of returning an empty dict.
+ return 'NOTPROVIDED'
+ else:
+ return token
+ _get_val = lazy(_get_val, str)
+
+ return {'csrf_token': _get_val() }
+
def debug(request):
"Returns context variables helpful for debugging."
context_extras = {}