Python+flask下,将某个字典{"a":1,"b":2,"c":3}传到前端,前端需要展示所有键值形式如下:
a=1
b=2
c=3
前端html中的如何写输出内容的代码?
Python代码部分
import flask
@app.route("/")
def index():
data = {"a": 1, "b": 2, "c": 3}
return render_template("index.html", data=data)
HTML代码部分
<html>
<body>
{% for key, value in data.items() %}
<p>{{ key }} = {{ value }}</p>
{% endfor %}
</body>
<html>