0

When I import bootstrap css and js to django as static, css file connected and works, but js file show me error: "GET /static/bootstrap/js/bootstrap.min.js HTTP/1.1" 404 179.

My 'main.html'

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    {% load static %}
    <!-- Bootstrap -->
    <link
      rel="stylesheet"
      href="{% static 'bootstrap/css/bootstrap.min.css' %}"
    />
    <!-- DataTables -->
    <!-- Bootstrap JS -->
    <script src="{% static 'bootstrap/js/bootstrap.min.js' %}" />
    <!-- DataTables JS-->
    <!-- DataTable Scripts -->
  </head>
  <body>
    {% include 'navbar.html' %}
    <main>
      <div class="container">
        {% if messages %} {% for message in messages %}
        <div class="alert alert-{{message.tags}}">{{message}}</div>
        {% endfor %} {% endif %} {% block context %} {% endblock context %}
        <footer class="footer">
          <div class="container">
            <p>© Copyright {% now "Y" %} by <a href=""></a></p>
          </div>
        </footer>
      </div>
    </main>
  </body>
</html>

My 'setting.py'

STATIC_URL = "static/"
STATICFILES_DIRS = [
    BASE_DIR / "static",
]

My project folder structure:

enter image description here

I need import css and js files as static, but django don't see js files, I don't understand what I'm doing wrong.

Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39
Vadym
  • 1
  • Does this answer your question? [Static Files not getting loaded in Django Python](https://stackoverflow.com/questions/53590409/static-files-not-getting-loaded-in-django-python) – Ivan Starostin Jul 19 '23 at 21:29
  • It didn't help. I still get the error: "GET /static/datatables/js/query.dataTables.min.js HTTP/1.1" 404 1971 – Vadym Jul 19 '23 at 21:45
  • Is it correct that the url `/static/bootstrap/js/bootstrap.min.js` can be opened with no error now but some other URLs are broken? – Ivan Starostin Jul 19 '23 at 22:06
  • I see you have included javascript files in head tag, try to move them all before closed body tag and let bootstrap file be first – Kanapek Jul 20 '23 at 01:31
  • Additionally, close the script tags like this: – Kanapek Jul 20 '23 at 01:44
  • This don't work, i replase into all position, add in end, create new project, but is don't help. I folow to all gide from youtube, but always the same error javascripts don't work. I download css and js from https://getbootstrap.com/ "Compiled CSS and JS". – Vadym Aug 03 '23 at 17:22
  • Ok, I found the error, need to import a 'bootstrap.bundle.min.js' file, instead of a 'bootstrap.min.js' file – Vadym Aug 05 '23 at 13:22

0 Answers0