404 or 500 error occurs when python django accesses static files

高洛峰
Release: 2017-02-14 13:58:31
Original
2211 people have browsed it

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',
)
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template