Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 烧瓶:返回烧瓶响应对象后重定向_Python_Flask - Fatal编程技术网

Python 烧瓶:返回烧瓶响应对象后重定向

Python 烧瓶:返回烧瓶响应对象后重定向,python,flask,Python,Flask,我正在开发一个web应用程序,运行一个shell脚本,并通过返回响应对象打印实时输出。有没有一种方法可以在shell脚本运行完毕后重定向到另一个页面 @app.route("/setup", methods=['POST', 'GET']) def setup(): def inner(): command = ["./test.bash", "exam"] proc = subprocess.Popen(command, stdout=subproces

我正在开发一个web应用程序,运行一个shell脚本,并通过返回响应对象打印实时输出。有没有一种方法可以在shell脚本运行完毕后重定向到另一个页面

@app.route("/setup", methods=['POST', 'GET'])
def setup():
    def inner():
        command = ["./test.bash", "exam"]
        proc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
        for line in iter(proc.stdout.readline,''):
            yield line.rstrip() + '<br/>\n'
    return Response(inner(), mimetype='text/html')
    # After this I want to redirect to another page say success.html
输出

这可能吗? 感谢您的帮助。提前感谢。

yield'document.location.href=http://redirect.me"


最后可能有用。。。这取决于浏览器是在解释流数据还是只是在转储流数据。也就是说,一个更好的技巧通常是在长时间运行的任务中使用芹菜之类的东西,然后使用js来对服务器进行互操作,看看它是否完成了

您可以返回一个HTML页面或重定向到另一个页面。如果您同时尝试这两种操作,用户将无法看到原始HTML,因为会立即重定向。您的意思是要运行一个连续脚本并在页面上从中获取实时输出吗?@AndrewCerevatkin:我可以从脚本中获取实时输出。但是一旦脚本运行,我想重定向到某个页面。在这种情况下,客户端javascript代码可能会工作得更好?例如制作事件侦听器或定期检查服务器是否有输出,如果有-通过更改location.href重定向
for line in iter(proc.stdout.readline,''):
    if line == "Success":
        # Redirect to success.html after returning Response object with script output
    else:
        # Redirect to error.html after returning Response object with script