【问题标题】:Translate django variable with html template value用 html 模板值翻译 django 变量
【发布时间】:2017-10-01 19:24:29
【问题描述】:

我想这样翻译:

<div class="col-sm-7 section">
   {{ template |safe }}
</div>

模板 = <div class="row"> <div class="calc-head">{% trans "Calculations" %}</div> </div>

但是 {% trans "Calculations" %} 对我不起作用。谁能帮帮我

【问题讨论】:

    标签: django python-3.x django-templates


    【解决方案1】:

    为什么使用模板作为变量?您是否将其作为字符串上下文对象添加到页面中? 将模板保存为 html 文件,记住

    {% load i18n %}
    

    在文件顶部,然后将您的代码(带有 html 内容)放入:

    {% blocktrans %}
    {# Your html markup here #}
    {% endblocktrans %}
    

    然后将其添加到您需要的页面中:

    {% include 'folder/name.html' %}
    

    希望对你有帮助。

    【讨论】:

    • 感谢您的回复,但我已将模板保存在数据库中,我需要将其呈现为变量。我在上下文中将模板作为变量传递
    • 好的。您仍然可以使用块格式。那不行吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    相关资源
    最近更新 更多