Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
62 views
in Technique[技术] by (71.8m points)

python - Why doesn't href from HTML to CSS work correctly with Django?

I have the next problem:

Im ceating a basic django webpage using HTML and CSS. The issue is that when I try to make the href from the HTML file to the CSS one:

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

It doesn't work correctly. my HTML file called "inicio.html" and "modelado.css" are in the same folder, but once I make the href, the console says this:

Not Found: /inicio/modelado.css

I think that the console is trying to find a folder called "inicio", but that's impossible since inicio is the HTML file from where I am running the program. What I want to know is if there is another way to write the direction, because that directory doesn't exist. I also think that this is a django related problem, because when I only use HTML, that line of code actually works when the files are in the same folder.

Thanks!

question from:https://stackoverflow.com/questions/65909534/why-doesnt-href-from-html-to-css-work-correctly-with-django

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

CSS is not a dynamic file (it is static) so by using

{% load static %}
<link rel="stylesheet" href="{% static 'yourstyle.css' %}">

you can load static files (like css).

More info here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...