mirror of
https://github.com/django/django.git
synced 2025-09-28 04:54:53 +00:00
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.
This commit is contained in:
parent
82e0cd1571
commit
8099d33b65
1 changed files with 2 additions and 4 deletions
|
@ -11,9 +11,8 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.middleware.csrf import get_token
|
from django.middleware.csrf import get_token
|
||||||
from django.utils import six
|
|
||||||
from django.utils.encoding import smart_text
|
from django.utils.encoding import smart_text
|
||||||
from django.utils.functional import lazy
|
from django.utils.functional import SimpleLazyObject, lazy
|
||||||
|
|
||||||
|
|
||||||
def csrf(request):
|
def csrf(request):
|
||||||
|
@ -30,9 +29,8 @@ def csrf(request):
|
||||||
return 'NOTPROVIDED'
|
return 'NOTPROVIDED'
|
||||||
else:
|
else:
|
||||||
return smart_text(token)
|
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):
|
def debug(request):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue