使用uWSGI和Nginx设置Flask非常困难,即使使用buildout脚本也需要很长时间,并且必须将其记录到稍后要再现的指令中.
如果我不计划服务器上的大负载(它是公开的隐藏),没有uWSGI运行它是否有意义?(Flask可以收听端口.Nginx可以转发请求吗?)
甚至不使用Nginx,只是在端口上运行裸烧瓶应用程序是否有意义?
uWSGI 可以同时作为 Web 服务器和应用程序服务器吗?
例如,独立的 WSGI 容器 https://flask.palletsprojects.com/en/1.1.x/deploying/wsgi-standalone/ 但同样,它建议使用 HTTP 服务器。为什么?uWSGI 不能处理 HTTP 请求吗?
我阅读了有关部署 Flask 应用程序的不同文章。他们说,我需要 uWSGI 和 nginx——一种流行的选择。
https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
https://flask.palletsprojects.com/en/1.1.x/deploying/uwsgi/#uwsgi
我的烧瓶应用程序。app_service.py
import json
import os
from flask import Flask, Response, redirect
portToUse = 9401
@app.route("/app/people")
def get_service_people():
print("Get people")
people_str = "{ \"John\", \"Alex\" }"
return Response(people_str, mimetype="application/json;charset=UTF-8")
if __name__ == "__main__":
app.run(host='0.0.0.0', port=portToUse)
Run Code Online (Sandbox Code Playgroud)
uwsgi配置uwsgi.ini
[uwsgi]
chdir = $(APPDIR)
wsgi-file = app_service.py
callable = app
uid …Run Code Online (Sandbox Code Playgroud) 我在我的Window系统上安装了Flask和HTML5.当我用IDLE启动Hello World!-program时,我在Python-Shell中收到一条红色消息:
"* Running on xxxx://127.0.0.1:5000/". (xxxx = http)
Run Code Online (Sandbox Code Playgroud)
当我用app.run(debug = True)启动时,会出现另一条红色消息:
"* Restarting with reloader".
Run Code Online (Sandbox Code Playgroud)
我的浏览器(Firefox)没有反应.如何在Firefox的新标签中获取"Hello World"?
守则是:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
return和app.run是indended