【发布时间】:2019-10-12 09:17:21
【问题描述】:
我需要使用 python flask 将 pandas 数据框中的数据添加到 html 文档的下拉列表中...
@app.route('/api/v1/resources/getservices', methods=['GET'])
def api_services():
return render_template('view.html',table=df.to_html())
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dropdown</title>
<h1>Services</h1>
</head>
<body>
<select name="table" method="GET" action="/">
<option value="{{table[0]}}" selected>{{table[0]}}</option>
{% for colour in table[1:] %}
<option value="{{colour}}">{{colour}}</option>
{% endfor %}
</select>
</body>
</html>
我期望的是,熊猫数据框 df 中“服务”列中的数据应作为项目添加到 html 文件的下拉列表中。但每当我尝试使用上述代码时,下拉创建的列表没有任何项目...
【问题讨论】:
-
前端调试的是什么(例如Chrome中的F12)?
-
python烧瓶和html
标签: python pandas flask dropdown