栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Flask

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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”正在显示,而没有任何刷新。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/366983.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号