user15084210
user15084210

Reputation:

Static folder django

I just created a django application, and I have a problem that I cannot resolve. I have 1 css file 'root.css' that I would like to link with my html database but it's like this /static/root.css was completely ignored. I arrive mostly at link /static/home/home.css on my home app.

enter image description here

This is not work (/templates/base.html) :

{% load static %}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-FR" lang="fr-FR">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
    <link rel="stylesheet" type="text/css" ref="{% static 'root.css' %}"> **// Not work**
    {% block css %}
    {% endblock %}
    <title>Learned</title>
</head>
<body>
    {% block content %}
    {% endblock %}
</body>
</html>

This is work (/home/templates.home.html) :

{% block css %}
    {% load static %}
    <link rel="stylesheet" type="text/css" href="{% static 'home/home.css' %}">
{% endblock %}

In my settings.py :

STATIC_URL = 'static/'
STATICFILES_DIRS = [
    BASE_DIR / "static"
]

Upvotes: 0

Views: 28

Answers (2)

user15084210
user15084210

Reputation:

OMG, I just understood the error! I just made a typo, I'm stupid I put "ref" instead of "href" in my first link. It sure works better like this: D

Upvotes: 1

mesmerlord
mesmerlord

Reputation: 48

Are you running this with Debug = False (production)? If so you need something else to serve the static files , check https://docs.djangoproject.com/en/3.1/howto/static-files/

Upvotes: 0

Related Questions