Home > Software design >  the css in my django project is not working
the css in my django project is not working

Time:04-05

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  type="submit">Submit</button>
</form>

{{woord}} <br/>
{{onder}}

{% endblock %}}

what can i do to make the style appear?

CodePudding user response:

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 setting.

settings.py import os

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static")

]

CodePudding user response:

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)

  • Related