【问题标题】:Django Collectstatic in Amazon Elastic Beanstalk Not WorkingAmazon Elastic Beanstalk 中的 Django Collectstatic 不工作
【发布时间】:2017-11-08 05:36:11
【问题描述】:

我已经在亚马逊弹性豆茎中部署了我的 Django 应用程序。但是,django 管理员中的 css 不起作用。我知道这是一个集体问题。这就是我的 settings.py 的样子:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

我的 ebconfig.config 文件中有这一行:

container_commands:
  01_collectstatic:
    command: "python manage.py collectstatic --noinput"

但是,这就是我在亚马逊上部署它后的样子: 我试过在亚马逊控制台中查看日志文件。我发现一行写着:

EmbeddedPostBuild/postbuild_0_dcape/Command 01_collectstatic] : Starting activity...
.....  
  0 static files copied to '/opt/python/bundle/33/app/static', 102 unmodified.

我需要做些什么来确保它有效?

【问题讨论】:

  • 我也不知道怎么把图片变小。有什么帮助吗?
  • 似乎 collectstatic 已经复制了我认为没有管理员的必要文件。现在你能描述一下你的文件夹结构吗
  • 为什么要给os.path.dirname打两次电话?
  • 我这里也有同样的问题。我的主应用程序中的 CSS 工作正常,但是管理员在实时服务器上的静态显示 404 的所有路径。

标签: python django amazon amazon-elastic-beanstalk django-staticfiles


【解决方案1】:

我遇到同样问题的时间最长。看来您必须告诉 beanstalk 您的静态文件夹在生产服务器上的位置。

在您指定 commands/container_commands 的 ebconfig.config 中添加选项设置,以便 beanstalk 可以知道您的 static_root 在实时服务器上的含义。

这就是我的做法:

settings.py

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

配置文件

option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: MDGOnline.settings
  "aws:elasticbeanstalk:container:python:staticfiles":
    "static/": "www/static/"

查看这个精彩的AWS Elastic Beanstalk Doc 了解更多详细信息

【讨论】:

    猜你喜欢
    • 2014-06-07
    • 2021-02-17
    • 1970-01-01
    • 2020-11-08
    • 2012-12-12
    • 2013-12-05
    • 2018-10-13
    • 2015-02-21
    • 2017-01-17
    相关资源
    最近更新 更多