【问题标题】:AWS Elastic Beanstalk can not find static files for Django AppAWS Elastic Beanstalk 找不到 Django App 的静态文件
【发布时间】:2020-09-28 01:35:17
【问题描述】:

我在为我创建的 django 应用程序设置弹性 beanstalk 上的静态文件夹时遇到了一些麻烦。我设法让应用程序在没有任何 css/js/etc 的情况下运行。我的文件结构是:

|.ebextensions
|    --django.config
|.elasticbeanstalk
|    --config.yml
|django_app
|    --core
|    --blog
|    --other apps..
|config
|    --settings
|        --base.py
|        --local.py
|        --production.py
|    --asgi.py
|    --urls.py
|    --wsgi.py
|static
|    --blog
|        --css/js/etc
|    --other apps
|manage.py
|requirements.txt
|secrets.json

在我的 django.config 中,我将其设置为:

option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: config.settings.production
  aws:elasticbeanstalk:container:python:
    WSGIPath: config.wsgi:application
    NumProcesses: 3
    NumThreads: 20

对于我在 base.py 中的静态设置(production/local.py 导入 base.py):

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

我在使用烧瓶时遇到了类似的问题,但它并没有给我带来这么多麻烦。我试图遵循这里的一些解决方案,但目前还没有任何效果,或者我误解了一些东西。任何帮助表示赞赏!

【问题讨论】:

    标签: python django amazon-web-services amazon-elastic-beanstalk static-files


    【解决方案1】:

    您必须在 django.config option_settings 中添加一个附加选项,这取决于您使用的 Elastic Beanstalk 平台。

    我认为您正在使用新平台platform/Python 3.7 running on 64bit Amazon Linux 2。如果是,请使用:

    aws:elasticbeanstalk:environment:proxy:staticfiles:
        /static: static
    

    但如果您使用的是platform/Python 3.6 running on 64bit Amazon Linux 或更早版本,请使用:

    aws:elasticbeanstalk:container:python:staticfiles:
        /static: static
    

    您可以查看link了解更多详情。

    如果您不知道您使用的平台,有不同的方法可以了解它:

    • 通过您的终端,它会出现在eb status 命令的输出中。
    • 通过 AWS 控制台,在您的 Elastic Beanstalk 环境页面中提及。

    【讨论】:

    • 这正是我所需要的,谢谢!不同版本有点混乱。
    • 我使用的是platform/Python 3.7 running on 64bit Amazon Linux 2,这解决了我的问题。非常感谢!
    猜你喜欢
    • 2020-11-15
    • 2012-12-12
    • 2018-08-09
    • 2018-10-16
    • 2018-12-27
    • 2020-11-08
    • 2019-04-27
    • 1970-01-01
    • 2018-05-18
    相关资源
    最近更新 更多