Question

The title says most of it. Python3.3 using a Pyramid app framework (-s starter) Adding this code to the views.py controller:

from HTMLParser import HTMLParser
h = HTMLParser()

string = '<p>Hi there!</p>';
return dict( string=h.unescape(string) )

where return dict(..) is handed off to a template with a simple ${string} marker in it, the result in the web browser is always to show the angle brackets instead of rendering them as tags. I.e, the web page shows: <p>Hi there!</p>

I need to be able to pass user content (html with markup) through to the template for it to render inline. What more do I need to do?

Was it helpful?

Solution

The templating engine is escaping the variable, because just about every templating engine does that.

You need to structure your templates to not escape variables. This differs in mako , chameleon, etc.

IIRC, the starter scaffold uses Chameleon's .pt templates.

If that's what your'e using, this other StackOverflow question answers your question fully: Python Pyramid & Chameleon templating language escapes html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top