我在python中有一個顯示名稱列表的函數。使用HTML調用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()
我想打電話給使用瓶
在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模板調用的問題。 – 2014-11-24 09:31:49
查看Jinja2文檔。當你在這裏時,Flask也是文檔。 – fr1tz 2014-11-24 09:39:32