How To Make Html Markup Show Up?
so I am new to HTML. I am building a web app with flask. I am trying to visualise some HTML markup, but it doen't show up properly. I have the following flask route: @app.route('/p
Solution 1:
The generated HTML is being escaped; you need to mark it as {{ htmlm|safe }}
.
As per the Jinja docs:
... The default configuration is no automatic escaping; for various reasons:
- Escaping everything except for safe values will also mean that Jinja is escaping variables known to not include HTML (e.g. numbers, booleans) which can be a huge performance hit.
- The information about the safety of a variable is very fragile. It could happen that by coercing safe and unsafe values, the return value is double-escaped HTML.
However, in Flask, auto-escaping is set as the default in many cases:
Unless customized, Jinja2 is configured by Flask as follows:
- autoescaping is enabled for all templates ending in .html, .htm, .xml as well as .xhtml when using render_template().
- autoescaping is enabled for all strings when using render_template_string(). a template has the ability to opt in/out autoescaping with the {% autoescape %} tag.
- Flask inserts a couple of global functions and helpers into the Jinja2 context, additionally to the values that are present by default.
Post a Comment for "How To Make Html Markup Show Up?"