【问题标题】:django template, using {% with %} to set a list vardjango 模板,使用 {% with %} 设置列表变量
【发布时间】:2020-12-08 17:32:04
【问题描述】:

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

【问题讨论】:

  • 也许尝试使用javascript插入列表变量?
  • @ha-neul 我忘了说我从不使用 django 模板,即使我使用其他类似的模板语言。我阅读了文档,但没有找到我要查找的内容,您能否更明确地了解您的解决方案? P.S 无法在电子邮件模板中使用 javascript

标签: django django-templates sendinblue


【解决方案1】:
{% with tt='123'|make_list %}
    {{ tt }}
    <hr>
    {% for x in tt %}
        {{ x }}<br>
    {% endfor %}
{% endwith %}

试试这个

【讨论】:

  • 我已经在文档中找到了这个过滤器,但我的数据比数字或字符数组更复杂。它是一个对象数组,我用它来动态组合 html(有地址、电话号码、姓名……)
猜你喜欢
  • 1970-01-01
  • 2021-09-12
  • 1970-01-01
  • 2018-01-11
  • 1970-01-01
  • 1970-01-01
  • 2021-07-23
  • 2012-11-13
  • 1970-01-01
相关资源
最近更新 更多