Flask

Flask,第1张

Flask

你可以简单地在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页面应如下所示。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><script type=text/javascript>        $(function() {          $('a#test').bind('click', function() { $.getJSON('/background_process_test',     function(data) {   //do nothing }); return false;          });        });</script>//button<div >    <h3>Test</h3>        <form> <a href=# id=test><button >Test</button></a>        </form></div>

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



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4892927.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存