ashwinx ashwinx - 6 months ago 25
HTML Question

CSS not linking to HTML

I have a HTML file and a CSS file in the same directory, but when I run the project, the CSS is not loaded and just the HTML appears. Below is the HTML code:

<link rel="stylesheet" type="text/css" href="/afc/Templates/afc/afc.css">

I tried using just the filename, it works if I just load that particular page but when I run the project, CSS does not get loaded.

<link rel="stylesheet" type="text/css" href="afc.css">

I also tried loading using CTRL+F5 to reload without cache, but didn't work.


I am getting this on the terminal:

Not Found: /afc/afc.css
[11/Oct/2016 18:55:30] "GET /afc/afc.css HTTP/1.1" 404 2853

I am using Django.


Django's HTML files are not static: they are templates. They are not served by the static server, but interpreted by Django itself. So there is no point in putting your CSS file in "the same directory" as the HTML file; that can't possibly work.

Instead, put your CSS in the static directory and link to it using Django's {% static %} tag. And learn about how to deploy the static files by reading the documentation.