Situation
- I have a django 3.0 application, I have built a few apps already in it that are functioning.
- That I have tried to create an authentication app for signup, login.
- The backend for the signup and login works.
- But the static files like .js, .css, images are not appearing.
- I also have a base.html file that contains all style sheet import and javascript imports that extends to this signup.html
- somehow if I fill up the signup.html file with nothing but just putting the extensions from the base.html file it still gives me the same errors
Folder Strudture
- mainapp-project
- mainapp (this is where I keep a base.html file that extends to the )
- secondapp (base.html file extends here)
settings.py
#actual folder name where we save our images
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'mainprojectfolder/static/')]
# Removed based on: https://stackoverflow.com/questions/60354519/django-base-html-extended-to-homepage-html-static-images-appear-but-home-css-d
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
#this_is_what_U_see_in_URL_bar_for_static_files
STATIC_URL = '/static/'
base.html
<!doctype html>
<html lang="en">
{% load static %}
<!-- SYLES & BASICS-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" type="image/png" href="{% static 'favicon.ico' %}"/>
<title> </title>
<link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/carousel/">
<link rel="stylesheet" href="static/css/bootstrap/bootstrap.min.css"> <!-- -->
<link href="static/css/style.min.css" rel="stylesheet">
</head>
<body>
<header>
...
</header>
{% block content %}
{% endblock %}
<script src="static/public/js/jquery/jquery.min.js"></script>
<script src="static/public/js/popper/popper.min.js"></script>
<script src="static/public/js/bootstrap/bootstrap.min.js"></script>
</body>
</html>
signin.html
{% extends 'ch/templates/base_emp.html' %}
{% load static %}
{% block content %}
<!-- MY COTENT, no imports only file requests-->
{% endblock %}
ERROR Message
[31/Mar/2020 12:31:22] "GET /accounts/signup HTTP/1.1" 200 19987
Not Found: /accounts/static/public/js/jquery/jquery.min.js
[31/Mar/2020 12:31:22] "GET /accounts/static/public/js/jquery/jquery.min.js HTTP/1.1" 404 3285
Not Found: /accounts/static/css/style.min.css
[31/Mar/2020 12:31:22] "GET /accounts/static/css/style.min.css HTTP/1.1" 404 3246
Not Found: /accounts/static/public/js/popper/popper.min.js
[31/Mar/2020 12:31:22] "GET /assets/images/logo-icon.png HTTP/1.1" 404 2808
Not Found: /accounts/static/css/bootstrap/bootstrap.min.css
[31/Mar/2020 12:31:22] "GET /accounts/static/public/js/popper/popper.min.js HTTP/1.1" 404 3285
Not Found: /accounts/static/public/js/bootstrap/bootstrap.min.js
[31/Mar/2020 12:31:22] "GET /accounts/static/css/bootstrap/bootstrap.min.css HTTP/1.1" 404 3288
[31/Mar/2020 12:31:22] "GET /accounts/static/public/js/bootstrap/bootstrap.min.js HTTP/1.1" 404 3303
Not Found: /accounts/static/public/js/popper/popper.min.js
[31/Mar/2020 12:31:22] "GET /accounts/static/public/js/popper/popper.min.js HTTP/1.1" 404 3285
Not Found: /accounts/static/public/js/bootstrap/bootstrap.min.js
[31/Mar/2020 12:31:22] "GET /accounts/static/public/js/bootstrap/bootstrap.min.js HTTP/1.1" 404 3303
Not Found: /accounts/static/public/js/jquery/jquery.min.js
[31/Mar/2020 12:31:22] "GET /accounts/static/public/js/jquery/jquery.min.js HTTP/1.1" 404 3285
Not Found: /accounts/static/public/js/popper/popper.min.js
[31/Mar/2020 12:31:22] "GET /accounts/static/public/js/popper/popper.min.js HTTP/1.1" 404 3285
Not Found: /accounts/static/public/js/bootstrap/bootstrap.min.js
[31/Mar/2020 12:31:22] "GET /accounts/static/public/js/bootstrap/bootstrap.min.js HTTP/1.1" 404 3303
[31/Mar/2020 12:31:22] "GET /static/favicon.ico HTTP/1.1" 200 15406
Correction Approaches
- GUIDE: In this post I have seen that I can pay with the following
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static') #if i turn on this I get another python related error
STATIC_URL = '/static/'
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)
- If I turn on this I get another python related error
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
- To be able to correct errors I have created a
/accounts/static/css/style.min.css
but I still got that error as well.Not Found: /accounts/static/css/style.min.css [31/Mar/2020 12:31:22] "GET /accounts/static/css/style.min.css HTTP/1.1" 404 3246
- This only answers general approaches that i already have done.
- Canging .js imports from this
<script src="static/public/js/jquery/jquery.min.js"></script>
<script src="static/public/js/popper/popper.min.js"></script>
<script src="static/public/js/bootstrap/bootstrap.min.js"></script>
- to this
<script src="{% static 'public/js/jquery/jquery.min.js' %}"></script>
<script src="{% static 'public/js/popper/popper.min.js' %}"></script>
<script src="{% static 'public/js/bootstrap/bootstrap.min.js' %}"></script>
- ERROR
Not Found: /accounts/static/css/style.min.css
Not Found: /accounts/static/images/small.png
Not Found: /accounts/static/css/bootstrap/bootstrap.min.css
[31/Mar/2020 13:51:06] "GET /accounts/static/css/style.min.css HTTP/1.1" 404 3246
[31/Mar/2020 13:51:06] "GET /accounts/static/images/small.png HTTP/1.1" 404 3270
[31/Mar/2020 13:51:06] "GET /accounts/static/css/bootstrap/bootstrap.min.css HTTP/1.1" 404 3288
- changing this
<link rel="stylesheet" href="static/css/bootstrap/bootstrap.min.css">
to this<link rel="stylesheet" href="{% static 'css/bootstrap/bootstrap.min.css %}">
gives the following error:
TemplateSyntaxError at /accounts/signup
Could not parse the remainder: ''css/bootstrap/bootstrap.min.css' from ''css/bootstrap/bootstrap.min.css'
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/signup
Django Version: 3.0
Exception Type: TemplateSyntaxError
Exception Value:
Could not parse the remainder: ''css/bootstrap/bootstrap.min.css' from ''css/bootstrap/bootstrap.min.css'
Exception Location: /Users/..../site-packages/django/template/base.py in __init__, line 662
Python Executable: /Users/..../bin/python3
Python Version: 3.7.3
Python Path:
['/Users/..../project',
'/Users/..../project/ven/lib/python37.zip',
'/Users/..../project/ven/lib/python3.7',
'/Users/..../project/ven/lib/python3.7/lib-dynload',
'/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
'/Users/..../lib/python3.7/site-packages']
Server time: Tue, 31 Mar 2020 14:00:00 +0000