I'm having difficulty referencing static files in my templates. I am using Twitter Bootstrap and have the bootstrap files (css, img, js) sitting at mysite/static.
I have set the STATIC_URL
, STATIC_ROOT
and TEMPLATE_CONTEXT_PROCESSORS
according to this tutorial. I have run ./manage.py collectstatic
which copied 72 files over. I have also added the below template tag to my template (index.html
) file but this hasn't worked.
{% load staticfiles %}
<link rel="stylesheet" href="{% static user_stylesheet %}" type="text/css" media="screen"/>
Any help on how to reference the files so that the bootstrap styling returns to the templates would be much appreciated!
Are you setting the
user_stylesheet
context variable in your view? You need to set that before you can pass it onto templates.I usually just use the
{{ static_url }}
tag for doing this stuff, so my code for including bootstrap components would be like.Assuming that bootstrap folder is present inside static.
EDIT
For your case, to set
user_stylesheet
context variable, you'll need to do something likeIt should be
And then something like
Update for Completeness
Folder Structure
Settings File
When you set
static_root
, for example:, all files are copied there, instead of in
project_root/static
. It is a new mechanism introduced in Django 1.3, to easy the static file processing: it will collect all files in eachSTATICFILES_DIR
and allstatic
dir under each installed app, so you copy them once in all.Refer the css/js files with
static_root
path.