python - 如何同时运行 python flask 应用程序和 webview
问题描述
我正在尝试同时运行烧瓶应用程序和 webview,但似乎只有烧瓶应用程序首先运行并阻止 webview 打开它。
if __name__ == '__main__':
os.system('python app.py')
webview.create_window('Hello world', 'http://127.0.0.1:5000/')
webview.start()
只有在我关闭烧瓶服务器(Ctr+C)后才会启动 Webview 命令,但直到那时 webview 返回连接被拒绝。
解决方案
您需要在后台运行烧瓶应用程序。这是一个示例工作示例。os.system('python app.py &')
主文件
import webview
import os
if __name__ == '__main__':
os.system('python app.py &')
webview.create_window('Hello world', 'http://127.0.0.1:5000/')
webview.start()
应用程序.py
# Importing flask module in the project is mandatory
# An object of Flask class is our WSGI application.
from flask import Flask
# Flask constructor takes the name of
# current module (__name__) as argument.
app = Flask(__name__)
# The route() function of the Flask class is a decorator,
# which tells the application which URL should call
# the associated function.
@app.route('/')
# ‘/’ URL is bound with hello_world() function.
def hello_world():
return 'Hello World'
# main driver function
if __name__ == '__main__':
# run() method of Flask class runs the application
# on the local development server.
app.run()
推荐阅读
- python - 查看使用 Heroku 和 S3 处理图像花费了太多时间
- c++ - 使用 cout 以某种格式打印数字(左对齐和右对齐)
- vb.net - 在 HTML 中使用 vb.net 每月播放一个视频
- jenkins - 来自 jenkins 的警告下一代插件 6.1.1 中使用了哪个版本的 Checkstyle?
- python - 根据另一列的值有条件地将渐变颜色应用于数据框单元格?
- mysql - 错误 1227 (42000):访问被拒绝;您需要(至少一个)在 SQL Workbench 中执行此操作的 SUPER 权限
- android - Android以编程方式更改可绘制纯色
- c# - 如何在文件C#中显示所有出现的特定单词
- css - Chrome,如何从 chrome Dev Tools 获取元素 css 样式 url()
- bash - 通过 ssh 使用 argjson 发送 jq