media_url context variable

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from django.conf import settings

def url_info(request):
    """Return useful variables to know the media url and, if you
    need it, your apps url."""

    return {
        'myapp_url': settings.MYAPP_URL,
        'media_url': settings.MEDIA_URL,
    }

More like this

  1. Cycling MEDIA_URL context processor by girasquid 3 years, 2 months ago
  2. Use MEDIA_URL in flatpages with SSL by gobble 1 year, 7 months ago
  3. Add site info to request context by bthomas 3 years, 2 months ago
  4. Template context processor to make the settings.py values available in templates by tamizhgeek 9 months ago
  5. Context processor for django admin app_list by alexander 1 year, 12 months ago

Comments

jwheare (on April 11, 2007):

I've been using a similar context processor for a while now and one caveat to be aware of is that error 500 templates aren't rendered with request context by default. This means that context processors are not applied and may lead to broken media references (style sheets/images).

You can work around this by pointing to your own handler500 view from your urlconf and using RequestContext instead of Context to render the template.

#

(Forgotten your password?)