使用Django中的变量更改HTML [英] Change HTML with variables in Django

查看:768
本文介绍了使用Django中的变量更改HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有dict latest_status:

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 %}

我正在尝试操作字体大小,这个dict,但是似乎不起作用。

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

推荐答案

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

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 %}

这篇关于使用Django中的变量更改HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆