Reputation: 55
How can I plug css into html by importing css from the main folder? I have a network project with 3 app.
network
--chat
--news
--static/style.css
...
My code:
{% load static %}
<link rel="stylesheet" href="{% style.css' %}">
It works if I create a static folder in some app, but I want to put it in the main network folder and then it stops working.
Upvotes: 0
Views: 31
Reputation: 5094
In your settings.py
;
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
Then inside your html files;
{% load static %}
<link rel='stylesheet' href="{% static 'styles.css' %}">
Explanation
first of all i am setting the STATIC_URL
which helps in the way that everytime you don't need to provide the path of the static files but use the syntax as i used ("{% static 'styles.css' %}"
).
After that i set the STATICFILES_DIRS
which sets the directories where the app should search for the static files which i set to the static
folder present in the base directory. You can set it as you want.
Upvotes: 2