Search code examples
pythonhtmlcssstatic-linkingdjango-staticfiles

can not link css file to django


This is html file where I linked the CSS file

{% load static %}
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>ShairuFitness</title>

    <script defer src="https://use.fontawesome.com/releases/v5.0.7/js/all.js"></script>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>

    <link rel="stylesheet" type="text/css" href="{% static 'fit/css/base.css' %}">

This is settings.py file

STATIC_URL = '/static/'
STATICFILE_DIRS = [os.path.join(BASE_DIR,'static'),]

This is location of file

static
 ->fit
   ->css
     ->base.css

ERROR

[10/Aug/2020 20:50:31] "GET /static/fit/css/base.css HTTP/1.1" 404 1674

Solution

  • Try with this settings:

    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
    STATIC_URL = '/static/'
    STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'static'),
    )
    

    The STATIC_ROOT is used to set up the path to your static files. Your can read more on the official doc.