首页 > 解决方案 > Elastic Beanstalk 不加载 Django 管理静态文件

问题描述

我在我的项目中的特定应用程序中有静态文件,我在我的配置文件中将该路由添加为我的 EB 静态路由,并且当我这样做时,这个 EB 不会为 django 管理页面加载所需的 CSS 文件。我的 python.config 看起来像:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: MyProject/wsgi.py
"aws:elasticbeanstalk:container:python:staticfiles":
/static/: "MyApp/static/"

我收到以下错误:

加载资源失败:服务器响应状态为 404(未找到)/static/admin/css/responsive.css:1

标签: djangodjango-adminamazon-elastic-beanstalk

解决方案


要告诉 Django 在哪里存储静态文件,请在 settings.py 中定义 STATIC_ROOT:

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = 'static'

并输入命令:

python manage.py collectstatic

推荐阅读