Home >Backend Development >Python Tutorial >404 or 500 error occurs when python django accesses static files
The content under the django static folder cannot be used and a 404 500 error appears
You need to check your settings file to ensure that there is the following content
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 started using eclipse, the DEBUG value in the settings file of the django project must be equal to True before static files can be accessed? I don’t quite understand this point
If you need to deploy it to a web site, you need to configure 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>
Thanks for reading, I hope you can This helps everyone, thank you for your support of this site!
For more related articles about 404 or 500 errors when accessing static files in python django, please pay attention to the PHP Chinese website!