diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index 9abc8d6a6c..99e547554b 100644 --- a/django/conf/global_settings.py +++ b/django/conf/global_settings.py @@ -144,6 +144,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.auth', 'django.core.context_processors.debug', 'django.core.context_processors.i18n', + 'django.core.context_processors.media', # 'django.core.context_processors.request', ) diff --git a/django/core/context_processors.py b/django/core/context_processors.py index f4b288dfc4..3c826b1a7d 100644 --- a/django/core/context_processors.py +++ b/django/core/context_processors.py @@ -42,6 +42,13 @@ def i18n(request): return context_extras +def media(request): + """ + Adds media-related context variables to the context. + + """ + return {'MEDIA_URL': settings.MEDIA_URL} + def request(request): return {'request': request} diff --git a/docs/settings.txt b/docs/settings.txt index d51f23fd51..7b281cbb23 100644 --- a/docs/settings.txt +++ b/docs/settings.txt @@ -776,7 +776,8 @@ Default:: ("django.core.context_processors.auth", "django.core.context_processors.debug", - "django.core.context_processors.i18n") + "django.core.context_processors.i18n", + "django.core.context_processors.media") A tuple of callables that are used to populate the context in ``RequestContext``. These callables take a request object as their argument and return a dictionary diff --git a/docs/templates_python.txt b/docs/templates_python.txt index 08a287f572..aaf109b659 100644 --- a/docs/templates_python.txt +++ b/docs/templates_python.txt @@ -294,7 +294,8 @@ return a dictionary of items to be merged into the context. By default, ("django.core.context_processors.auth", "django.core.context_processors.debug", - "django.core.context_processors.i18n") + "django.core.context_processors.i18n", + "django.core.context_processors.media") Each processor is applied in order. That means, if one processor adds a variable to the context and a second processor adds a variable with the same @@ -390,6 +391,15 @@ See the `internationalization docs`_ for more. .. _LANGUAGE_CODE setting: ../settings/#language-code .. _internationalization docs: ../i18n/ +django.core.context_processors.media +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If ``TEMPLATE_CONTEXT_PROCESSORS`` contains this processors, every +``RequestContext`` will contain ``MEDIA_URL``, providing the +value of the `MEDIA_URL setting`_. + +.. _MEDIA_URL setting: ../settings/#media-url + django.core.context_processors.request ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~