[英]Loader with python & flask
I make a premise: I'm working on a school project and the technologies that I can use are: python, flask, bootstrap, JavaScript and JQuery. 我有一个前提:我正在做一个学校项目,可以使用的技术有:python,flask,bootstrap,JavaScript和JQuery。
I have a button (that I will call to "Update Product") that "onclick" must enable one of these buttons: https://www.w3schools.com/howto/howto_css_loading_buttons.asp , the "Update Product" button must be hidden and must call a function in python (example: updateProducts ()). 我有一个按钮(我将其称为“更新产品”),“ onclick”必须启用以下按钮之一: https : //www.w3schools.com/howto/howto_css_loading_buttons.asp ,“更新产品”按钮必须为隐藏并且必须在python中调用一个函数(例如:updateProducts())。 At the end of this function (the function returns ok or ko), I return the message (using flash), but I do not know how to hide the Loading button and show the "Update Product" button again. 在此函数结束时(该函数返回ok或ko),我返回了消息(使用Flash),但是我不知道如何隐藏“正在加载”按钮并再次显示“更新产品”按钮。
Can you help me? 你能帮助我吗?
Here is one way. 这是一种方法。
When you render the template in python you could pass a variable to control the visibility of the button. 当您使用python渲染模板时,您可以传递一个变量来控制按钮的可见性。
render_template('page.html', visible=True)
Then, on your page perhaps something like this (found at Hiding a button in Javascript and adapted) 然后,在您的页面上可能是类似这样的内容(可在Javascript中隐藏按钮并进行修改)
<script>
var hidden = {{ visible|safe }};
function action() {
if(hidden) {
document.getElementById('button').style.visibility = 'hidden';
} else {
document.getElementById('button').style.visibility = 'visible';
}
}
You can also change the variable with an onclick function on then page itself. 您还可以在页面本身上使用onclick函数更改变量。 Your button to call a python function could look something like this. 您调用python函数的按钮可能看起来像这样。
<input type="button" id="toggler" value="Toggler" onClick="/funcionName" />
Remember to use the @app.route("/functionName")
before the python function. 请记住,在python函数之前使用@app.route("/functionName")
。
Hope this is close to what you wanted. 希望这接近您想要的。
Here are the steps to achieve this. 这是实现此目的的步骤。
When you click update Product button, following things should happen. 当您单击更新产品按钮时,应该发生以下情况。
$(".update_button").on("click", function(e){ $(".loading_button").show(); // show loading button $(".update_button").hide(); // hide update button $.ajax({}) // send ajax request to update product, on success, hide loader and show update button });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.