Skip to content Skip to sidebar Skip to footer

How Do I Get Html Tags In Variables To Work?

My code looks like this Python: render = web.template.render('templates/', base='layout') . . . fileout_text = codecs.open(filename_text, 'r', 'utf-8').read() text = markdown.markd

Solution 1:

Your template system is escaping the HTML as a security measure. You need to tell the template that the HTML output by Markdown is "safe". Based on your code, I'm assuming you are using web.py. The web.py docs state:

By default, Templetor uses web.websafe filter to do HTML-encoding.

>>> render.hello("1 < 2")
"Hello 1 &lt; 2"

To turnoff filter use : after $. For example:

The following will not be html escaped.
$:form.render()

So in your template try this:

$def with text
     < text>$:text < /text>

Adding the colon ($:text) will tell the template system to not escape the HTML.

If I guessed incorrectly and you are not using web.py, then tell us which templating system you are using and perhaps we can point you to the right solution. Although, now that you know what the problem is, you could just search the docs for that templating system and find the answer yourself.


Solution 2:

Print out your variable, to see that you're not encoding your html tags.

Probably that "<" is encoded for &lt; and ">" is encoded for &gt;, that's why it's showing HTML code in your browser.


Post a Comment for "How Do I Get Html Tags In Variables To Work?"