0

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.

1 Answer 1

1

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' %}">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.