In my view, if I specify
def myView(request):
return render_to_response('myTemplate.html', {'user': request.user,},
context_instance=RequestContext(request))
then I can access settings such as STATIC_URL in myTemplate.html.
However, if I specify
def myView(request):
return render_to_response('myTemplate.html', {'user': request.user,})
then I cannot access STATIC_URL. In this latter case, {{ STATIC_URL }} just yields an empty string in the rendered page. In the former case, {{ STATIC_URL }} yields the proper string for the static URL (“/static/”).
Why do I need to send a request context to access the STATIC_URL setting in my template?
I am running Django 1.4 on Apache 2.
Read the docs for a better answer. But there is the short answer:
This is because of DRY (Don´t Repeat Yourself), think this: what if you need set the same variable in all the templates through all the views?: context_processors, are methods that add variables to your templates in a more ordered way.
I quote: