app.py
@app.route("/"):
def text():
text = render_template('test.html')
myDict = dict({"ersterTeil":"<div>sda<div>"})
return reder_template('test1.html', myDict=mydict)
和我的HTLM代码
<body>
{% for text1, text2 in myDict.items() %}
{{ text1 }}
{{ text2 }}
</body>
现在的问题是打印是带有HTML标记的。我该怎么解决呢?
在模板内部,使用安全筛选器将字符串显式标记为安全HTML({{myvariablesafe}})
https://flask.palletsprojects.com/en/1.1.x/templating/#controll-autoescaping
那么,在你的情况下。
<body>
{% for text1, text2 in myDict.items() %}
{{ text1|safe }}
{{ text2|safe }}
</body>
尽管如此,请确保那些text
变量确实是安全的,否则可能会导致安全问题。