【问题标题】:How to make heroku automatically run compilemessages just as it runs collectstatic如何让heroku在运行collectstatic时自动运行compilemessages
【发布时间】:2015-04-03 04:04:52
【问题描述】:
python manage.py compilemessages

根据locale/en/LC_MESSAGES/django.po 等翻译源文件名称创建名为locale/en/LC_MESSAGES/django.mo 的编译翻译文件。

我希望 *.mo 文件被 git 忽略并且不提交到存储库,因为这些不是源文件。

Heroku 已经知道如何执行

python manage.py collectstatic

用于 django 项目。

如何让它也执行compile messages

目前我通过将编译结果文件 (*.mo) 添加到我的存储库来解决此问题,但我想知道是否有更好的方法。

(如果相关 - 我网站的仓库:https://github.com/yairchu/vote_tool

【问题讨论】:

    标签: django heroku


    【解决方案1】:
    1. 在您的项目根目录中创建一个文件:bin/post_compile
    2. 添加行./manage.py compilemessages
    3. git push origin
    4. git push heroku

    当您将分支推送到 Heroku 时,它现在应该运行该命令。我不确定自定义bin/post_compile 文件是否会覆盖Heroku 所做的自动检测,所以如果您发现它不再运行collectstatic,只需将该行插入您的compilemessages 行下,但添加@987654329 @ 到该行,这样管理命令就不会提示您键入“是”来确认您要覆盖现有文件。

    【讨论】:

    • 这对我来说失败了,因为 gettext 没有安装在 Heroku 实例上。 Can't find msgfmt. Make sure you have GNU gettext tools 0.15 or newer installed.
    • 我设法使用 gettext buildpack 安装了 gettext:elements.heroku.com/search/buildpacks?q=gettext
    猜你喜欢
    • 1970-01-01
    • 2016-02-01
    • 2021-09-06
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 2014-02-08
    • 1970-01-01
    相关资源
    最近更新 更多