【发布时间】:2014-11-24 09:27:52
【问题描述】:
我在 python 中有一个显示名称列表的函数。
def search():
with open('business_ten.json') as f:
data=f.read()
jsondata=json.loads(data)
for row in jsondata['rows']:
#print row['text']
a=str(row['name'])
print a
return a
search()
我正在尝试使用 Flask 在 HTML 文件中调用此函数
{% extends "layout.html" %}
{% block content %}
<div class="jumbo">
<h2>Welcome to the Rating app<h2>
<h3>This is the home page for the Rating app<h3>
</div>
<body>
<p>{{ search.a }}</p>
</body>
{% endblock %}
我的路由文件如下:
from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello gugugWorld!'
@app.route('/crawl')
def crawl():
return render_template('crawl.html')
【问题讨论】:
-
1.请修正你的缩进。 2. 这不是关于从 HTML 调用(可能涉及 Ajax)而是从 Jinja2 模板调用的问题。
-
查看 Jinja2 文档。当您使用它时,Flask 文档也是如此。