我想构建一个混合应用程序(嵌入到桌面应用程序中的 Web 技术)。
我将从 Web 版本开始,并使用 WebKit 嵌入它,但我不希望嵌入版本通过 TCP 端口服务请求。
使用 WebKit(Qt、Gtk),我可以拦截所有 URL 请求并对其进行操作。
我缺少的是一种无需通过 TCP(或 WSGI)即可调用 Flask URL 可调用调度程序的方法。
还有比使用调试器分析调用堆栈更好的想法吗?
最佳答案
Simon Sapin 在(相当活跃的)Flask 邮件列表上回复:
Why not WSGI ?
You have to get a Python interpreter somewhere. Then you need to call your application somehow with data from WebKit like the URL being requested, and get the response. WSGI is just that: a calling convention for Python functions (or other callable objects.)
If WSGI is more complex than you’d like, you can use the test client:
- http://flask.pocoo.org/docs/api/#flask.Flask.test_client
- http://werkzeug.pocoo.org/docs/test/#werkzeug.test.Client
- http://werkzeug.pocoo.org/docs/test/#werkzeug.test.EnvironBuilder
That’s how I do it in Frozen-Flask. It simulates HTTP requests to a Flask app at the WSGI level and write the responses to static files. The test client is just an easier way to make WSGI calls:
https://github.com/SimonSapin/Frozen-Flask/blob/master/flaskext/frozen/__init__.py#L228
WSGI really is Flask’s "entry point".
Other than that if you’re interested in Flask inner workings start looking from here:
https://github.com/mitsuhiko/flask/blob/master/flask/app.py#L1477
关于python - 在没有 TCP 端口的情况下通过 Flask 调度 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7758988/