Change HTML with variables in Django

独自空忆成欢 提交于 2019-12-11 07:06:29

问题


I have the dict latest_status:

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

I am trying to make a text cloud by doing something like this in my template:

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

I am trying to manipulate the font size with the count from the dict but it doesn't seem to be working.


回答1:


The <style> tag is used to introduce a block (or external resource) containing style definitions. You'll want to encapsulate your text in a presentation tag of some sort--for example:

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


来源:https://stackoverflow.com/questions/5228717/change-html-with-variables-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!