I know this question was previously asked and I already tried many different configurations to fix this. I had no problem serving my static files locally when developing but, if I remember correctly (don't know exactly because of the browser cache), I ran python manage.py collectstatic
and then all static files were nowhere to be found:
[15/May/2023 08:55:59] "GET /static/js/script.js HTTP/1.1" 404 179
[15/May/2023 08:55:59] "GET /static/admin/css/responsive.css HTTP/1.1" 404 179
...
Here is my settings.py
:
DEBUG = ENV.bool("DEBUG") # set to True
INSTALLED_APPS = [
"django.contrib.staticfiles",
...
]
STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / STATIC_PATH # I have checked that the path is correct
STATICFILES_DIRS = [ # I tried with and without STATICFILES_DIRS
BASE_DIR / "vhsapp" / "static"
]
urls.py
...
if settings.DEBUG:
urlpatterns += [
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT),
]
base_site.html
{% extends "admin/base_site.html" %}
{# TEMPLATE EXTENSION FOR THE DEFAULT ADMIN INTERFACE #}
{% load static %}
{% block extrahead %}
{{ block.super }}
<link rel="icon" type="image/x-icon" href="{% static 'img/favicon.png' %}"> <!-- 404 error -->
<script>
const APP_NAME = "{{ APP_NAME }}"; // variable defined correctly
</script>
{% endblock %}
Project arborescence
project_root/
├── staticfiles/ # all static files are inside this directory
├── templates/
│ └── admin/
│ └── base_site.html
├── vhs/
│ ├── .env
│ ├── urls.py
│ └── settings.py
├── vhsapp/
│ ├── static/ # additional static files (collectstatic put them inside staticfiles/)
│ ├── templates/ # additional templates
│ └── __init__.py
└── manage.py
I have read the docs but I really cannot see what might have happened. I know the project arborescence is a little weird but everything used to work!
Do you have any idea what i am missing?
Thank you X1000