Ticket #1278: 1278.diff

File 1278.diff, 2.8 KB (added by James Bennett, 17 years ago)

Patch adding a 'media' context processor and associated documentation

  • django/conf/global_settings.py

     
    138138    'django.core.context_processors.auth',
    139139    'django.core.context_processors.debug',
    140140    'django.core.context_processors.i18n',
     141    'django.core.context_processors.media',
    141142#    'django.core.context_processors.request',
    142143)
    143144
  • django/core/context_processors.py

     
    4242
    4343    return context_extras
    4444
     45def media(request):
     46    """
     47    Adds context variables for the admin media prefix and the base
     48    media URL.
     49   
     50    """
     51    return {'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX,
     52            'MEDIA_URL': settings.MEDIA_URL }
     53
    4554def request(request):
    4655    return {'request': request}
    4756
  • docs/settings.txt

     
    718718
    719719    ("django.core.context_processors.auth",
    720720    "django.core.context_processors.debug",
    721     "django.core.context_processors.i18n")
     721    "django.core.context_processors.i18n",
     722    "django.core.context_processors.media")
    722723
    723724A tuple of callables that are used to populate the context in ``RequestContext``.
    724725These callables take a request object as their argument and return a dictionary
  • docs/templates_python.txt

     
    291291
    292292    ("django.core.context_processors.auth",
    293293    "django.core.context_processors.debug",
    294     "django.core.context_processors.i18n")
     294    "django.core.context_processors.i18n",
     295    "django.core.context_processors.media")
    295296
    296297Each processor is applied in order. That means, if one processor adds a
    297298variable to the context and a second processor adds a variable with the same
     
    387388.. _LANGUAGE_CODE setting: ../settings/#language-code
    388389.. _internationalization docs: ../i18n/
    389390
     391django.core.context_processors.media
     392~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     393
     394If ``TEMPLATE_CONTEXT_PROCESSORS`` contains this processors, every
     395``RequestContext`` will contain these two variables:
     396
     397    * ``ADMIN_MEDIA_PREFIX`` -- The value of the `ADMIN_MEDIA_PREFIX setting`_.
     398    * ``MEDIA_URL`` -- The value of the `MEDIA_URL setting`_.
     399
     400.. _ADMIN_MEDIA_PREFIX setting: ../settings/#admin-media-prefix
     401.. _MEDIA_URL setting: ../settings/#media-url
     402
    390403django.core.context_processors.request
    391404~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    392405
Back to Top