diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2015-02-08 12:24:11 -0600 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-02-08 15:03:29 -0500 |
| commit | d54638727ae23e8dc1e1ed0823efbd15806d9778 (patch) | |
| tree | 888c9126b45cb25e3d73b536bb7c36de91d3011f | |
| parent | ee86bf24d269869012d5538c22d37588cec68685 (diff) | |
[1.8.x] Simplified the lazy CSRF token implementation in csrf context processor.
This significantly improves performance on PyPy. The previous
implementation would generate a new class on every single request,
which is relatively slow.
Backport of 8099d33b6553c9ee7de779ae9d191a1bf22adbda from master
| -rw-r--r-- | django/template/context_processors.py | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/django/template/context_processors.py b/django/template/context_processors.py index dcd737f4ae..a81fe71829 100644 --- a/django/template/context_processors.py +++ b/django/template/context_processors.py @@ -11,9 +11,8 @@ from __future__ import unicode_literals from django.conf import settings from django.middleware.csrf import get_token -from django.utils import six from django.utils.encoding import smart_text -from django.utils.functional import lazy +from django.utils.functional import SimpleLazyObject, lazy def csrf(request): @@ -30,9 +29,8 @@ def csrf(request): return 'NOTPROVIDED' else: return smart_text(token) - _get_val = lazy(_get_val, six.text_type) - return {'csrf_token': _get_val()} + return {'csrf_token': SimpleLazyObject(_get_val)} def debug(request): |
