diff options
Diffstat (limited to 'django/template/context_processors.py')
| -rw-r--r-- | django/template/context_processors.py | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/django/template/context_processors.py b/django/template/context_processors.py index 25ac1f2661..32753032fc 100644 --- a/django/template/context_processors.py +++ b/django/template/context_processors.py @@ -19,17 +19,18 @@ 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' + return "NOTPROVIDED" else: return token - return {'csrf_token': SimpleLazyObject(_get_val)} + return {"csrf_token": SimpleLazyObject(_get_val)} def debug(request): @@ -37,46 +38,52 @@ def debug(request): Return context variables helpful for debugging. """ context_extras = {} - if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS: - context_extras['debug'] = True + if settings.DEBUG and request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS: + context_extras["debug"] = True from django.db import connections # Return a lazy reference that computes connection.queries on access, # to ensure it contains queries triggered after this function runs. - context_extras['sql_queries'] = lazy( - lambda: list(itertools.chain.from_iterable(connections[x].queries for x in connections)), - list + context_extras["sql_queries"] = lazy( + lambda: list( + itertools.chain.from_iterable( + connections[x].queries for x in connections + ) + ), + list, ) return context_extras def i18n(request): from django.utils import translation + return { - 'LANGUAGES': settings.LANGUAGES, - 'LANGUAGE_CODE': translation.get_language(), - 'LANGUAGE_BIDI': translation.get_language_bidi(), + "LANGUAGES": settings.LANGUAGES, + "LANGUAGE_CODE": translation.get_language(), + "LANGUAGE_BIDI": translation.get_language_bidi(), } def tz(request): from django.utils import timezone - return {'TIME_ZONE': timezone.get_current_timezone_name()} + + return {"TIME_ZONE": timezone.get_current_timezone_name()} def static(request): """ Add static-related context variables to the context. """ - return {'STATIC_URL': settings.STATIC_URL} + return {"STATIC_URL": settings.STATIC_URL} def media(request): """ Add media-related context variables to the context. """ - return {'MEDIA_URL': settings.MEDIA_URL} + return {"MEDIA_URL": settings.MEDIA_URL} def request(request): - return {'request': request} + return {"request": request} |
