您可以这样在ajax请求中编写有效负载:
$(document).ready(function(){var clicked;$(".favorite").click(function(){clicked = $(this).attr("name");$.ajax({ type : 'POST', url : "{{url_for('test')}}", contentType: 'application/json;charset=UTF-8', data: {'data':clicked}}); });});在烧瓶端点中,可以按以下方式提取值:
@app.route('/test/', methods=['GET','POST'])def test(): clicked=None if request.method == "POST": clicked=request.json['data'] return render_template('test.html')


