您可以在AJAX的帮助下完成此操作…
下面是一个调用python函数的示例,该函数在不重定向或刷新页面的情况下打印hello.
在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 simple按钮时,您可以看到“Hello”显示没有任何刷新.