So, I want access to the MEDIA_URL settings in my templates. The template context processor
django.core.context_processors.media provides that, right? Well, only if your template gets passed an instance of
django.template.RequestContext. This doesn’t happen automatically if you use
django.shortcuts.render_to_response in your view function. If you want to reference MEDIA_URL in a base template which is extended by many other templates, then you can either add RequestContext instances to your views, or roll your own shortcut function which perhaps wraps render_to_response, etc.
Wouldn’t it be simpler if you could just get the MEDIA_URL as needed in your template without having to place this burden on your views? It’s a bit strange that Django doesn’t provide a template tag for MEDIA_URL, since it does provide one for ADMIN_MEDIA_PREFIX. Perhaps the logic is that template context processors are global to a site (i.e., affecting all RequestContext instances), and MEDIA_URL is globally applicable, whereas ADMIN_MEDIA_PREFIX only applies to the admin site.
In addition to these issues I discovered that under certain conditions, such as those triggering server errors, the template context processors do not fire. So, for example, any dependencies in your 500.html template will not render properly. Not a huge issue in the larger scope of things, but why not fix that, too. No sense combining a server error with a crappy-looking error page if you can easily avoid it.