我想将html链接中的值传递给flask中的函数:
警察姓名旁边有一个按钮,如果单击它,我应该获取其id并将其发送到python函数这里是
html代码
:
<ul class="list-group">
{% for p in policemen %}
<li class="list-group-item">{{ " "~ p.rank ~" "}}
<div class="col-md-2 text-center">
<a href='/deletepolice/{{p.id}}' class="btn btn-primary btn-lg" >
</div> Delete ?
</a>
</li>
{% endfor %}
下面是python函数:
@app.route('/deletepolice/<string:id>', methods=['GET','POST'])
def deletepolice(id):
# Create cursor
cur = mysql.connection.cursor()
# Execute
cur.execute("DELETE FROM police WHERE id = %s", [id])
# Commit to DB
mysql.connection.commit()
#Close connection
cur.close()
flash('Police man deleted', 'success')
return redirect(url_for('policemen'))