如何在django模板中使用“{”字符

时间:2021-04-30 20:13:23

I know we use {{ }} characters for variables but I want to show my datas between {} characters

我知道我们对变量使用{{}}个字符,但我想在{}个字符之间显示我的数据

I want to show November{12} like that. So what I did is:

我想像那样展示11月{12}。所以我做的是:

<ul>
    {% for month in archive %}
<li><a href="?{{month.date|date:"Y-m"}}">{{month.date|date:"F Y"}}{{{month.count}}}</a></li>
    {% endfor %}
</ul>

But I got an error like that:

但是我得到了这样的错误:

Could not parse the remainder: '{month.count' from '{month.count'

无法解析余数:'{month.count'来自'{month.count'

How to use { character in template?

如何在模板中使用{字符?

2 个解决方案

#1


2  

<ul>
    {% for month in archive %}
<li><a href="?{{month.date|date:"Y-m"}}">{{month.date|date:"F Y"}}&#123;{{month.count}}&#125;</a></li>
    {% endfor %}
</ul>

#2


-1  

render the { and } as b_s and b_e to your template and do this:

将{和}作为b_s和b_e渲染到模板中并执行以下操作:

<ul>
{% for month in archive %}
<li><a href="?{{month.date|date:"Y-m"}}">{{month.date|date:"F Y"}} {{b_s}} {{month.count}}      {{b_e}}</a></li>
{% endfor %}

#1


2  

<ul>
    {% for month in archive %}
<li><a href="?{{month.date|date:"Y-m"}}">{{month.date|date:"F Y"}}&#123;{{month.count}}&#125;</a></li>
    {% endfor %}
</ul>

#2


-1  

render the { and } as b_s and b_e to your template and do this:

将{和}作为b_s和b_e渲染到模板中并执行以下操作:

<ul>
{% for month in archive %}
<li><a href="?{{month.date|date:"Y-m"}}">{{month.date|date:"F Y"}} {{b_s}} {{month.count}}      {{b_e}}</a></li>
{% endfor %}