使用spycopg2 Python填充HTML选择

使用spycopg2 Python填充HTML选择,python,html,postgresql,flask,psycopg2,Python,Html,Postgresql,Flask,Psycopg2,我是新的使用烧瓶和 我想使用FLASK提取该数据并将其显示为html表单中的选择选项。 这是我的选择 <span class="input-group-addon">Unity</span> <select name="unity" class="selectpicker form-control"> </select> 我怎么能做到 Python代码: @app.route(“/statdistics/unity”) def

我是新的使用烧瓶和 我想使用FLASK提取该数据并将其显示为html表单中的选择选项。 这是我的选择

<span class="input-group-addon">Unity</span>
    <select name="unity" class="selectpicker form-control">

    </select>
我怎么能做到

Python代码:

@app.route(“/statdistics/unity”)
def unity():
db=get_db()
cursor=db.cursor()
cursor.execute(“从mse.unity中选择unity”)
unity=cursor.fetchall()
返回渲染模板('my\u html\u file.html',unity=unity)
HTML,使用Jinja2作为循环:


{unity%中u的%s}
{{u}
{%endfor%}
Flask包含Jinja2模板引擎默认情况下,您可以将选择的变量传递给HTML模板,当您调用
render\u template()
时,请查看文档以了解更多详细信息:

@app.route("/stadistics/unity")
def unity():
    db = get_db()
    cursor = db.cursor()
    cursor.execute("select unity from mse.unity")
    unity = cursor.fetchall()
    print (unity)