django - 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
解决方案
要告诉 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
推荐阅读
- reactjs - 如何为仅将 props 传递给 Child 的组件定义 propTypes
- postgresql - PostgreSQL 在同一个事务中创建视图和导入外部模式
- haskell - 有没有办法让 Haskell 中的“拆分”函数接受两种不同类型的输入?
- .net - 无法生成 cookie Web API
- asynchronous - 使用不同结果类型时,在 dotnet 核心中使用 Task.WhenAll 的最佳实践
- c# - 在 Selenium C# 中使用 xpath 查找 webtable 中的总行数
- unit-testing - 为什么 Spock Framework 建议使用 SUS,但在任何示例中都没有这样的缩写?
- sql-server - 使用 Microsoft SQL Server Management Studio 将 SQL Server 数据库转储(数据和模型)从一个环境传输到另一个环境
- typescript - Joi 验证集合?
- python - Ubuntu 上使用的 PyInstaller - CentOS 上使用的压缩文件 - 错误