如果要执行功能而不生成对服务器的请求,则必须在Javascript中定义功能。否则,您需要触发HTTP请求。
现在,根据您的情况,如果您只想尝试启用/禁用按钮,那么就可以使用javascript来完成所有操作(无需转到服务器)。
例:
<button type="button" onclick="disableButton(this)" name="enable">Enable</button>
javascript
function disableButtonState(elem) { if(confirm('Are you sure you want to disable this button?') == true) { elem.disabled = true; alert("its done."); } else { return false; } }</script>但是,如果要在服务器上调用某个方法(例如发送电子邮件),则应使用
formPOST / GET或
AJAXPOST / GET
例:
app.py
@app.route('/foo', methods=['GET', 'POST'])def foo(x=None, y=None): # do something to send email pass模板
<form action="/foo" method="post"> <button type="submit" value="Send Email" /></form>
当您单击“发送电子邮件”按钮时,HTTP POST请求将发送到应用程序上的“ /
foo”。
foo现在,您的函数可以从请求中提取一些数据,并在服务器端执行它想做的任何事情,然后将响应返回到客户端Web浏览器。
建议使用Flask教程更好地了解使用Flask构建的Web应用程序时客户端/服务器交互。



