Home  >  Article  >  Backend Development  >  404 or 500 error occurs when python django accesses static files

404 or 500 error occurs when python django accesses static files

高洛峰
高洛峰Original
2017-02-14 13:58:312067browse

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


   ServerName www.mydjangosite.com
   ServerAlias mydjangosite.com
   ServerAdmin fake@mydjangosite.com

   DocumentRoot /path/to/mydjangosite
   
       Options FollowSymLinks
       AllowOverride None
       Order allow,deny
       allow from all
   

   Alias /static/ /path/to/mydjangosite/static/
   
       Order allow,deny
       allow from all
   

   # 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

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn