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.
asked Mar 8, 2011 at 5:30
super9
30.3k42 gold badges125 silver badges172 bronze badges
-
"doesn't seem to be working"? What does the output source look like, and what should it look like?Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2011年03月08日 05:33:37 +00:00Commented Mar 8, 2011 at 5:33
-
A row of words with different sizes based on the font-size.super9– super92011年03月08日 05:45:27 +00:00Commented Mar 8, 2011 at 5:45
1 Answer 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 %}
answered Mar 8, 2011 at 5:35
Ori
4,2302 gold badges27 silver badges27 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
super9
sweet that works but is there anyway I can just return them inline? I'm not very good with html/css. Right now, every word is a new line.
Daniel Roseman
Use
span instead of p. Although seriously, if you're doing web development you need to know enough HTML/CSS to know the difference between block and inline elements.super9
@daniel Yeah, I'm kinda slowly working through the list. I have the bare minimum basics in HTML/CSS but I'm getting there! :)
lang-py