我最近设法通过 EB CLI 将我的 Django Web 应用程序设置并部署到 AWS,Web 应用程序上的一切看起来都很好,但是当我访问管理面板时,我注意到静态文件根本没有加载(但在本地服务器上加载正常) . 我在 S3 存储桶上看到管理静态文件以以下结构上传(我的应用程序称为 wfi_workflow):
.elasticbeanstalk admin/css/fonts/img/js/resources/wfi_workflow/
有关静态文件,请参阅我的项目中的以下相关代码:
设置
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/static/'
STATICFILES_DIRS = [ os.path.join(BASE_DIR,'static') ]
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
.ebextensions/django.config
container_commands:
01_sh_executable:
command: find .platform/hooks/ -type f -iname "*.sh" -exec chmod +x {} \;
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: wfi_workflow.settings
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
/static_files: static_files
aws:elasticbeanstalk:container:python:
WSGIPath: wfi_workflow.wsgi:application
.ebextensions/packages.config
packages:
yum:
python3-devel: []
mariadb-devel: []
.platform/hooks/predeploy/01_migrations.ssh
#!/bin/bash
source /var/app/venv/*/bin/activate
cd /var/app/staging
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py collectstatic --noinput
非常感谢您的帮助,谢谢。