![](/img/trans.png)
[英]How can I load a Python flask app into a gtk webview (Webkit)
[英]How to run python flask app and webview simultaneosuly
I am trying to run flask app and webview simultaneously but it seems that only flask app is running first and blocking the webview to open it.
if __name__ == '__main__':
os.system('python app.py')
webview.create_window('Hello world', 'http://127.0.0.1:5000/')
webview.start()
Webview 命令仅在我关闭 flask 服务器(Ctr+C)后才启动,但在此之前 webview 返回连接被拒绝。
您需要在后台运行 flask 应用程序。 这是一个示例工作示例。 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.