Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static CSS file not loading in Django framework

I'm running on localhost but stylesheet isn't working

Here is my project setup:

-main
   -main
   -home
      -templates
         -home
             -index.html
   -static
      -css
         -style.css

My settings.py:

STATICFILES_DIRS = [
    "/static/",
]

STATIC_URL = '/static/'

index.html:

{% load staticfiles %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
    <title>My Home Page</title>
    <link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}" />
</head>
<body>
<p>My Content</p>
</body>
</html>

Here is what my server outputs: "GET /static/css/style.css HTTP/1.1" 404 1652

What is wrong?

like image 887
James Mitchell Avatar asked Jul 29 '26 14:07

James Mitchell


1 Answers

Okay this change seemed to fix it:

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    '/static/',
]
like image 91
James Mitchell Avatar answered Aug 01 '26 03:08

James Mitchell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!