Django: automatically import MEDIA_URL in context
- by pistacchio
Hi,
like exposed here, one can set a MEDIA_URL in settings.py (for example i'm pointing to Amazon S3) and serve the files in the view via {{ MEDIA_URL }}. Since MEDIA_URL is not automatically in the context, one have to manually add it to the context, so, for example, the following works:
#views.py
from django.shortcuts import render_to_response
from django.template import RequestContext
def test(request):
return render_to_response('test.html', {}, context_instance=RequestContext(request))
This means that in each view.py file i have to add from django.template import RequestContext and in each response i have to explicitly specify context_instance=RequestContext(request).
Is there a way to automatically (DRY) add MEDIA_URL to the default context? Thanks in advance.