0

I've already invoked collectstatic with no effect

Errors from chrome:

Failed to load resource: the server responded with a status of 404 (Not Found) logo.png':1
Failed to load resource: the server responded with a status of 404 (Not Found) bootstrap.bundle.min.js:1
Failed to load resource: the server responded with a status of 404 (Not Found) lightbox.min.js:1
Failed to load resource: the server responded with a status of 404 (Not Found) main.js:1
Failed to load resource: the server responded with a status of 404 (Not Found) all.css:1
Failed to load resource: the server responded with a status of 404 (Not Found) style.css:1
Failed to load resource: the server responded with a status of 404 (Not Found) bootstrap.css:1
Failed to load resource: the server responded with a status of 404 (Not Found)lightbox.min.css:1
Failed to load resource: the server responded with a status of 404 (Not Found)

settings.py

STATIC_ROOT= os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATIC_DIRS = [os.path.join(BASE_DIR, 'btre/static')]

base.html

{% load static %}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="{% static 'css/all.css' %}">
    <link rel="stylesheet" href="{% static 'css/bootstrap.css' %}">
    <link rel="stylesheet" href="{% static 'css/style.css' %}">
    <link rel="stylesheet" href="{% static 'css/lightbox.min.css' %}">
    <title>BT Real Estate</title>
</head>
<body>
  {% include 'partials/_topbar.html' %}
  {% include 'partials/_navbar.html' %}

{% block content %}
{% endblock %}   

{% include 'partials/_footer.html' %}

<script src="{% static 'js/jquery-3.3.1.min.js' %} "></script>
<script src="{% static 'js/bootstrap.bundle.min.js' %} "></script>
<script src="{% static 'js/lightbox.min.js' %} "></script>
<script src="{% static 'js/main.js' %} "></script>
</body>
</html>

My directories:

btre_project

Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39
Elah
  • 11
  • 6
  • 1
    Does this answer your question? [django html template can't find static css and js files](https://stackoverflow.com/questions/66437690/django-html-template-cant-find-static-css-and-js-files) – Ivan Starostin Mar 22 '21 at 17:06
  • Try remove btre from `STATIC_DIRS = [os.path.join(BASE_DIR, 'btre/static')]` make it `STATIC_DIRS = [os.path.join(BASE_DIR, 'static')]` – seif Mar 22 '21 at 17:08
  • 1
    Take a look at option names carefully under given link. It's not `STATIC_DIRS`, it's `STATICFILES_DIRS`. Also I guess you have not enabled `APP_DIRS`. And there was no reason to check file urls since files do not get copied into `STATIC_ROOT` after running `collectstatic` - note, this would be a better question, more specific (why files don't get copied). – Ivan Starostin Mar 22 '21 at 17:08
  • Got it. Thank you all. Especially @IvanStarostin, I changed STATIC_DIRS to STATICFILES_DIRS and it worked. – Elah Mar 22 '21 at 17:15

1 Answers1

0

If you work on a legacy code and you are working on your localhost, you have to either set debug to true (in your settings file) to apply css statics from localhost, or add to your url option to serve static files from Django code, which is not recommended. Normally statics should be served from a separate server. So just turn Debug to True, and it should work.

Kf H.
  • 131
  • 1
  • 4