I accessed the Django management site in my local development environment, The css (static file) could not be read on the management site as shown below.
Python 3.7.4
Django 2.2.6
virtualenv 16.1.0
$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
November 02, 2019 - 16:45:33
Django version 2.2.6, using settings 'studysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[02/Nov/2019 16:24:55] "GET /admin/ HTTP/1.1" 200 3080
[02/Nov/2019 16:24:55] "GET /static/admin/css/responsive.css HTTP/1.1" 404 77
[02/Nov/2019 16:24:55] "GET /static/admin/css/dashboard.css HTTP/1.1" 404 77
[02/Nov/2019 16:24:55] "GET /static/admin/css/base.css HTTP/1.1" 404 77
Apparently css can't be read.
I checked settings.py
to find out the cause.
settings.py
# snip
DEBUG = False
ALLOWED_HOSTS = ['localhost','0.0.0.0']
# snip
The above DEBUG = False
was suspicious, so if you set it to True, css can be read.
DEBUG = False is supposed to be a production environment, and it seems that static files are read from a web server such as nginx.
In order for css to be loaded, it is necessary to support ** either ** of the following two.
If set to True, css in the project will also be loaded.
python manage.py runserver --insecure
commandWith the --insecure option, the css in your project will be loaded.
settings.py
DEBUG = False
ALLOWED_HOSTS = ['*']
Css was not applied with this setting. It seems that css cannot be read just by setting ALLOWED_HOSTS arbitrarily.
Recommended Posts