'the css in my django project is not working
Please help me out. I don't get any errors in my css file or in finding it, but still the style i would like is not shown.
my css file
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
h2 {
color: deeppink !important;
}
my html page
{% extends 'base.html' %}
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static '../static/css/style.css' %}">
{% block content%}
<h1>All synonymes will be shown here</h1>
<form method=POST action="{% url 'add-vocabulair' %}">
{% csrf_token %}
<input type="search" placeholder="valt onder" aria-label="Search" name="onder" value={{key}}><br/>
<input type="search" placeholder="woord" aria-label="Search" name="woord"><br/>
<button class="btn btn-outline-secondary" type="submit">Submit</button>
</form>
{{woord}} <br/>
{{onder}}
{% endblock %}}
what can i do to make the style appear?
Solution 1:[1]
To get started, check settings.py file : STATIC_URL and STATIC_ROOT settings. You must have a Static directory at the root of the layout. If everything is configured correctly, it should look like this.
href="{% static 'css/style.css' %}"
In settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"))
P.S - Dont forgen about Nginx static configs (if you work in production server)
Solution 2:[2]
First you check that your static folder is inside the app or it is outside, if it is outside then add one thing inside the settings.
settings.py
:
import os
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static")
]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | David Grigoryev |
Solution 2 | ahuemmer |