静态文件未在我的Django项目的生产中加载。我正在使用mod-wsgi来提供静态文件。
静态文件在开发中运行良好(当DEBUG = True时),但是现在在尝试调用静态文件时出现404错误。
我的文件结构是: https://imgur.com/a/FuFZSSh
/etc/apache2/sites-available/mysite.conf
<VirtualHost *:80>
ServerName <ip address>
ErrorLog ${APACHE_LOG_DIR}/mysite-error.log
CustomLog ${APACHE_LOG_DIR}/mysite-access.log combined
WSGIDaemonProcess mysite processes=2 threads=25 python-path=/var/www/mysite
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
Alias /robots.txt /var/www/mysite/static/robots.txt
Alias /favicon.ico /var/www/mysite/static/favicon.ico
Alias /static/ /var/www/mysite/static/
Alias /media/ /var/www/mysite/media/
<Directory /var/www/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /var/www/mysite/static>
Require all granted
</Directory>
<Directory /var/www/mysite/media>
Require all granted
</Directory>
</VirtualHost>
settings.py
STATIC_ROOT = '/var/www/mysite/static_root/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
STATIC_URL = '/static/'
MEDIA_ROOT = '/var/www/mysite/media/'
MEDIA_URL = '/media/'
任何帮助将不胜感激:)
答案 0 :(得分:0)
答案 1 :(得分:0)
运行collectstatic
之后,Apache应该查看您的STATIC_ROOT目录。
<Directory /var/www/mysite/static_root>
Require all granted
</Directory>