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.
JavaScript
x
3
1
{% load staticfiles %}
2
<link rel="stylesheet" href="{% static user_stylesheet %}" type="text/css" media="screen"/>
3
Any help on how to reference the files so that the bootstrap styling returns to the templates would be much appreciated!
Advertisement
Answer
It should be
JavaScript
1
2
1
{% load static %}
2
And then something like
JavaScript
1
4
1
<!-- path -->
2
<link href="{% static 'bootstrap/css/bootstrap.css' %}" rel="stylesheet" type="text/css">
3
<!--->
4
Update for Completeness
Folder Structure
- proj
- app1
- app2
- myproj_public
- static
- css
- bootstrap.css
- js
- xyz.js
- css
Settings File
JavaScript
1
5
1
STATIC_ROOT = os.path.join(os.path.abspath(
2
os.path.join(PROJECT_ROOT, 'myproj_public', 'static')), '')
3
4
STATIC_URL = '/static/'
5