A 404 or 500 error occurred when python django accessed a static file
- 2020-05-24 05:46:31
- OfStack
The content method under the django static folder does not have a 404 500 error
You need to check your settings file to make sure it has 1
import os
PROJECT_ROOT = os.path.dirname(__file__)
DEBUG = True
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
If the project is launched using eclipse, the django project settings file must have the DEBUG value equal to True static file for access. This point is not clear
If you need to deploy to the web site you need to configure the static file mapping in apache
<VirtualHost *:80>
ServerName www.mydjangosite.com
ServerAlias mydjangosite.com
ServerAdmin fake@mydjangosite.com
DocumentRoot /path/to/mydjangosite
<Directory /path/to/mydjangosite>
Options FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /static/ /path/to/mydjangosite/static/
<Directory /path/to/mydjangosite/static>
Order allow,deny
allow from all
</Directory>
# The following installs the Django WSGI app
WSGIDaemonProcess www.mydjangosite.com processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup www.mydjangosite.com
WSGIScriptAlias / /path/to/mydjangosite/wsgi.py
</VirtualHost>
Thank you for reading, I hope to help you, thank you for your support of this site!