首页 > 解决方案 > django 模板,使用 {% with %} 设置列表变量

问题描述

我需要在 django 模板中硬设置一个列表。我知道我必须传递变量to the template,而不是创建它们in the template,但我只能访问模板文件。我将 sendinblue 与自定义模板一起使用,使用注入模板的自定义参数的唯一方法是使用他们的 api。我只需要硬编码列表中的一些内容,内容会根据联系人动态显示,我认为仅为此使用api是大材小用。

标签: djangodjango-templatessendinblue

解决方案


{% with tt='123'|make_list %}
    {{ tt }}
    <hr>
    {% for x in tt %}
        {{ x }}<br>
    {% endfor %}
{% endwith %}

尝试这个


推荐阅读