xx
1. 启动命令中添加 Gunicorn 的 --reload 选项,这将启用 Gunicorn 的自动重载功能,并在代码更改时重新启动应用程序
gunicorn --bind 0.0.0.0:8000 --reload --access-logfile '-' app:app
2. 设置 Flask 应用程序的 debug 标志,以便在调试模式下运行应用程序。
if __name__ == '__main__':
app.run(debug=True)
3. 使用 Flask 的调试器,您需要禁用 Gunicorn 的访问日志,以便在控制台上查看调试器输出。
gunicorn --bind 0.0.0.0:8000 --reload --access-logfile '-' app:app
远程调试flask
参考:https://dev.to/pacheco/dockerize-a-flask-app-and-debug-with-vscode-34i1
launch.json
{
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "0.0.0.0",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/code"
}
]
}
]
}
docker-compose.yml
FLASK_APP: manage:app
entrypoint:
[
"python",
"-m",
"debugpy",
"--listen",
"0.0.0.0:5678",
"-m",
"manage",
"--wait-for-client",
"--multiprocess",
"-m",
"flask",
"run",
"-h",
"0.0.0.0",
"-p",
"5000"
]
ports:
- 5000:5000
- 5678:5678
中文返回
app.config[“JSON_AS_ASCII”] = False
app.config[“RESTFUL_JSON”] = {“ensure_ascii”: False}
session中概念
id, name
S: session ID 通过cookie 给出