gpt4 book ai didi

python - 在 Django 中使用变量更改 HTML

转载 作者:太空宇宙 更新时间:2023-11-04 09:18:50 26 4
gpt4 key购买 nike

我有字典 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 %}

我正在尝试使用字典中的计数来操纵字体大小,但它似乎不起作用。

最佳答案

<style>标签用于引入包含样式定义的 block (或外部资源)。您需要将您的文本封装在某种表示标记中——例如:

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

关于python - 在 Django 中使用变量更改 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5228717/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com