Elah
Elah

Reputation: 21

Can't load static files in Django:

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

Upvotes: 0

Views: 685

Answers (1)

Kf H.
Kf H.

Reputation: 151

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.

Upvotes: 0

Related Questions