skip to Main Content

Please tell me what the error is. After running the python manage.py collectstatic files were generated, the js scripts work, but the css file is not connected.

base.html

<!doctype html>
{% load static %}
<html lang="en">
  <head>
   ....
    <!--Custome CSS-->
    <link rel="stylesheet" href="{% static 'static/css/style.css' %}">
    <title>{% block title %} {% endblock %}</title>
  </head>

Folder:
enter image description here

settings.py

STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / STATIC_URL

I tried adding the code from the documentation:

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

2

Answers


  1. Use below.

    <link rel="stylesheet" href="{% static 'css/style.css' %}">
    
    Login or Signup to reply.
  2. if your css file is into the static folder then you have to write like this,

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

    and when in static folder there is another folder like css folder so, at that time you have to write like this,

    <link rel="stylesheet" href="{% static 'css/style.css' %}">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search