Pretty popular question on here...
My template is rendering, but the {{ STATIC_URL }} variable is either empty or non-existent. I am using django 1.4.
Using the variable in my template:
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}app/backbone_project/core.css">
Opening up the console in my browser I see that this is the URL being requested: http://machine-name:8000/backbone/app/backbone_project/core.css
So, STATIC_URL
is not returning anything, i.e. if I take it out of the template the URL stays the same.
<link rel="stylesheet" type="text/css" href="app/backbone_project/core.css">
also returnshttp://machine-name:8000/backbone/app/backbone_project/core.css
.
EDIT
My settings.py file did not have TEMPLATE_CONTEXT_PROCESSORS
by default so I did not think it was required. I have added it now like this:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.static',
)
There is an error after doing so: Put 'django.contrib.auth.context_processors.auth' in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.
So, I added what it suggested like this:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.static',
)
The end result here is the same initial problem described above.
EDIT 2
I have removed TEMPLATE_CONTEXT_PROCESSORS
completely from my settings (as it was in the default implementation of the project.) This is the code of my view:
views.py (not much to see here):
def homepage(request):
return render_to_response('backbone_project/index.html', {'data':'none'})
EDIT 3
I changed my view to use context_instance=RequestContext(request)
so that now it looks like this:
from django.template import RequestContext # and other imports
def homepage(request):
return render_to_response('backbone_project/index.html', {'data':'none'}, context_instance=RequestContext(request))
The initial problem still persists.