html按钮调用python_Flask-在按钮OnClick事件上调用python函数

小编典典

你可以简单地在AJAX的帮助下完成此操作…这是一个示例,该示例调用python函数,该函数在不重定向或刷新页面的情况下打印问候。

在app.py中,将其放在代码段下方。

#rendering the HTML page which has the button

@app.route('/json')

def json():

return render_template('json.html')

#background process happening without any refreshing

@app.route('/background_process_test')

def background_process_test():

print ("Hello")

return ("nothing")

并且你的json.html页面应如下所示。

$(function() {

$('a#test').bind('click', function() {

$.getJSON('/background_process_test',

function(data) {

//do nothing

});

return false;

});

});

//button

Test

Test

在这里,当你按下控制台中的“测试简单”按钮时,你可以看到“ Hello”正在显示,而没有任何刷新。

2020-04-05

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值