Im new to django and have two filter questions:
I have this code:
{% for tip in tips %}
<p>some text {{ tip }} some more text</p>
{% endfor %}
My problem is that the output is:
some text
this is the tip
some more text
Question #1)
How do I filter it (or disable the default filter for this) so it appears like this:
some text this is the tip some more text
Question #2)
If the tip included
<b>Tip</b>
how woul开发者_如何学JAVAd I get the text to be bold instead of printing the html markup?
Thanks!
Answer 1)
<p>
{% for tip in tips %}
some text {{ tip }} some more text
{% endfor %}
</p>
Answer 2)
Mark the content of tip as safe by using {{ tip|safe }}
. But Please be aware that this might be a security hole if the content of tip
is somehow user supplied. It might lead to Cross-site scripting if someone could enter Javascript code intp tip.
精彩评论