Django: automatically import MEDIA_URL in context

Posted by pistacchio on Stack Overflow See other posts from Stack Overflow or by pistacchio
Published on 2010-05-21T09:00:40Z Indexed on 2010/05/21 9:10 UTC
Read the original article Hit count: 205

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about django

Related posts about python