等待python脚本完成时浏览器超时

2024-10-01 09:31:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在Flask上运行一个web服务器,我想在脚本createHTML.py完成后呈现一个html(index.html)

@app.route('/scan')
def cakes():
    os.system('python3 createHTML.py')
    return render_template('index.html')

由于这个脚本需要太长的时间,我得到一个错误,说该网站没有发送任何信息

我怎么能阻止这一切?有没有办法让网站等到脚本完成后再显示页面

这是在按钮上运行的html:

<div style="text-align:center;">
    <button href="scan" id="realScanButton" type="button">Scan Network</button>
</div>

这是重定向到python函数的脚本:

<script>
$( document ).ready(function() {
    $("#realScanButton").click(function() {
       clickEnBotonScan(); 
      });
});
function clickEnBotonScan(){
    $("#realScanButton").html('Scanning...');
    $("#realScanButton").attr('disabled','disabled');
    window.location.href = 'http://localhost:5000/scan';
    return true;
}


Tags: pydiv脚本indexscanreturn网站html