I am using Mako templates to create a web page.
There is a section in which I prevent html escaping using | n. However, inside, I also need to show some user generated entries for which I need to escape the HTML on the view side of the apps.
What is the way to go with Pyramid for this?
I know there is CGI escaping but it does not seem as good as Mako’s own and I would like to use that.
currently I have:
from pyramid.compat import escape
escape(str)
Thank you!
According to the pyramid docs,
pyramid.compat.escapeprovidescgi.escape(html.escapeon Python 3).According to the mako docs, the escape functionality is provided by
markupsafe.escape(x). One thing to keep in mind that might be helpful is that MarkupSafe will look for an__html__method on the object it is escaping, and if it finds it, it will call that method and use the results as the escaped string. This might allow you some flexibility in how certain items are escaped.You can either use one of these, or another option is (if possible) to change your template so that the escaping actually does happen in the template rather than the view.