I am trying to dockerize a django app. It looks like it has not been configured for development / debug mode before so I have added some settings around static content
What I can say is that the application launches ok, and serves pages but I am getting errors in the browser console such as
“Refused to apply style from ‘http://localhost:8000/static/css/styles.css’ because its MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.”
This is to be expected as the content returned is a 404 page, which isn’t css so I get it, that’s ok.
Here’s where it gets weird. If I ssh into the running docker container and run
python manage.py findstatic css/styles.css
It successfully finds the file! So I would suppose the StaticFile finders are able to understand the configuration.
I am running the server with DEBUG mode turned on. This is confired by a print command in the settings file.
The config settings I have are as follows
STATIC_URL = ‘static/’
STATICFILES_DIRS = [
BASE_DIR / ‘static/’
]
The folder structure of the project is such that
<project_root>
/static
/css
styles.css
So I would expect the django.contrib.staticfiles.finders.FileSystemFinder to be able to use the setting in STATICFILES_DIRS to be able to find the file at css/styles.css
As I say this works on the cli inside the container.
I tried to set logging to DEBUG by adding the following
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
},
},
"root": {
"handlers": ["console"],
"level": "WARNING",
},
"loggers": {
"django": {
"handlers": ["console"],
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"),
"propagate": False,
},
},
}
But the logged output does not look any more verbose, e.g.
[24/Jan/2025 16:09:26] “GET /static/css/styles.css HTTP/1.1” 200 4300
Further info
Django 4.5 running on Docker using python:3.11 container image
So, can someone give me some pointers as to how to go about debugging / troubleshooting this?