Reputation: 1
I am aware that there are other posts on this, however, none of the answers have helped fix my issue. I am making a django project and would like to use some basic css on my page, however it does not seem to be linking. The html file is in a folder called templates, while the css is in a folder called static. Here is what I used to link my css.
<link rel="stylesheet" type="text/css" src='../static/style.css'>
And my css file looks like this:
body {
background: black;
}
h1 {
color: white;
}
Any help would be appreciated.
Upvotes: 0
Views: 58
Reputation: 73
The method you used is for only connecting HTML to CSS normally but in your case your code should look like this:
<link rel="stylesheet" type="text/css" src="{% static 'path/to/file/' %}">
and don't forget to put {% load static %}
at the top of your file.
Note: the 'path/to/file' should start from within the static dir.
Example: For a file structure like this:
|--static
| |-- css
| |-- styles.css
Your link should look like this:
<link rel="stylesheet" type="text/css" src="{% static 'css/styles.css' %}">
Upvotes: 1