django - 在 Django 模板中包含 Mercurial 变更集 ID(或修订版)的最佳方法是什么?

标签 django mercurial

我正在开发一个 Django 网站,并使用 hg 进行版本控制。我想将变更集 id 嵌入到网站的页脚中,就像 Stackoverflow 和 Bitbucket 在其页脚中所做的那样。实现这一目标的最佳方法是什么?

我必须使用 Mercurial api 吗?有没有办法让 hg 从 CLI 中仅输出修订 ID,以便我可以在部署脚本中捕获该内容,并在模板中包含简单的文本输出?

您使用过的方法将不胜感激。谢谢

最佳答案

参见:KeywordPlan

在发布到生产的过程中,使用 hg id 从 Mercurial 获取当前版本信息。您可以轻松地将其存储在一个文件中,然后将其包含在 Django 模板中。

例如,在发布时使用的任何脚本/流程中,请执行以下操作:

hg id >templates/id.html

然后在主 Django 模板的底部(或其他位置)添加:

Revision:  {{ include "templates/id.html" }}

(注意:路径/目录可能会有所不同,具体取决于您在 Django 中配置模板路径的方式)。

关于django - 在 Django 模板中包含 Mercurial 变更集 ID(或修订版)的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5149270/

相关文章:

git - TortoiseHg/Mercurial <=> TortoiseGit <=> TortoiseSvn/Subversion的快速比较

python - Mercurial CGI (hgweb.cgi) 失败

node.js - 将 Nginx 设置为 Nodejs 和 Django 的代理

mercurial - Mercurial 中有没有办法删除本地提交?

bash - 我怎么知道 `hg push` 何时失败(而不是 "no changes")

mercurial - 如何配置 Mercurial 在 merge 时使用 Kompare?

python - 为 Django 用户定义 "remaining time off"的正确方法

python - django-filter:使用 ChoiceFilter 并根据请求进行选择

Django Heroku 引发 ValueError ("Missing staticfiles manifest entry for ' %s'"% clean_name)

python - python中的模拟函数参数