Shell脚本打开Flask驱动的网页会打开两个窗口 [英] Shell script opening flask powered webpage opens two windows

查看:45
本文介绍了Shell脚本打开Flask驱动的网页会打开两个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一些同事编写一个小型的本地运行的烧瓶式Web应用程序.他们不是超级精通技术,所以我希望他们能够简单地双击一个链接来运行Shell脚本,这将启动Flask服务器,然后在其Mac上弹出打开localhost页面.

I'm writing a small locally-running flask powered web app for some coworkers. They aren't super technologically savvy so I'd like them to be able to simply double click a link to run a shell script, which will start the flask server and then pop open the localhost page on their macs.

我已经创建了一个简单的文件 start :

I've created a simple file start:

python server.py
open http://localhost:5000

但是它将弹出两个打开的页面-首先是localhost(但显示无法连接"消息),然后是localhost再次运行.太奇怪了!

But it pops open two webpages - first the localhost (but with an "unable to connect" message) and then the localhost again with it working. So odd!

我尝试在python中使用 webbrowser 模块,但这具有相同的效果:

I tried using the webbrowser module in python, but this has the same effect:

if __name__ == '__main__':
    app.debug = True
    webbrowser.open("http://localhost:5000/")
    app.run()

并放在后面:

if __name__ == '__main__':
    app.debug = True
    app.run()
    webbrowser.open("http://localhost:5000/")

仅在服务器关闭后打开页面.

only opens the page after the server is shutdown.

有什么想法吗?我猜他们可以关闭不工作的页面,但是功能不是很流畅.

Any ideas? I guess they could just close the non-working page, but it isn't very smooth functionality.

推荐答案

使用线程.看到这个相关的职位.

use threads. See this for a relevant post.

python webbrowser.open(url)

这篇关于Shell脚本打开Flask驱动的网页会打开两个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆