在Django中用变量修改HTML

1 投票
1 回答
2646 浏览
提问于 2025-04-16 13:13

我有一个叫做 latest_status 的字典:

{'What': 10, "Study'": 10, 'all': 10, 'to': 10, "facebook'": 10, 'has': 10, 'worth': 20, 'hurting': 10 }

我想在我的模板里做一个文字云,方法是这样:

{% for word,count in latest_status.items %}
<style="font-size:{{ count }}px"> {{ word }}</style> 
{% endfor %}

我想根据字典里的数量来调整字体大小,但好像没有成功。

1 个回答

5

<style>标签用来引入一个包含样式定义的块(或者外部资源)。你会想把你的文本放在某种展示标签里,比如:

{% for word,count in latest_status.items %}
<p style="font-size:{{ count }}px;"> {{ word }}</p>
{% endfor %}

撰写回答