【发布时间】:2020-05-29 19:40:31
【问题描述】:
我设法将一个 JSON 文件调用到我的路由器中并访问模板中的内容。但是,我想知道是否有更简单的方法来调用我的数据。有没有办法只打电话给{{ title }},而不是{{ data["title"] }}?任何帮助将不胜感激。
router_article_02.py
@app.route('/article-02/welcome')
def article_02_welcome():
with app.open_resource("templates/article-02/data.json", "r" ) as data_file:
data = json.load(data_file)
return render_template("article-02/welcome.html", data = data)
article-02.html
<h1>{{ data["title"] }}</h1>
<div class="overline">Category: {{ data["category-type"] }}</div>
【问题讨论】: