mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
[py3] Made csrf context processor return Unicode
This commit is contained in:
@@ -6,12 +6,15 @@ and returns a dictionary to add to the context.
|
||||
These are referenced from the setting TEMPLATE_CONTEXT_PROCESSORS and used by
|
||||
RequestContext.
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.middleware.csrf import get_token
|
||||
from django.utils.encoding import smart_bytes
|
||||
from django.utils import six
|
||||
from django.utils.encoding import smart_text
|
||||
from django.utils.functional import lazy
|
||||
|
||||
|
||||
def csrf(request):
|
||||
"""
|
||||
Context processor that provides a CSRF token, or the string 'NOTPROVIDED' if
|
||||
@@ -23,10 +26,10 @@ def csrf(request):
|
||||
# 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 b'NOTPROVIDED'
|
||||
return 'NOTPROVIDED'
|
||||
else:
|
||||
return smart_bytes(token)
|
||||
_get_val = lazy(_get_val, str)
|
||||
return smart_text(token)
|
||||
_get_val = lazy(_get_val, six.text_type)
|
||||
|
||||
return {'csrf_token': _get_val() }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user