这里用的是 Flask + flasgger 的 Swagger 集成,要进到它的 Web 界面,主要有两步:先把后端跑起来,然后访问对应的 URL。
- 启动后端服务
在 Windows 终端里执行(路径按你的项目来):
cd d:\projects\aperbio\ap-webapi\ap-webapi
python manage.py
manage.py 里这样写的:
- 端口: SERVER_PORT = 11001
- 启动: app.run(host=’0.0.0.0′, port=SERVER_PORT)
所以本机启动后,API 服务监听在 http://localhost:11001/ 。
- 访问 Swagger UI
startup.py 里是这样初始化的:
swagger_config = Swagger.DEFAULT_CONFIG
Swagger(app, config=swagger_config)
没有修改 specs_route ,所以 flasgger 使用默认的文档地址 /apidocs/ 。
本机直接访问:
- http://localhost:11001/apidocs
- 或者 http://localhost:11001/apidocs/index.html
就能看到 Swagger 的 Web 界面。
- 如果是部署环境
- 如果通过 IP 访问: http://<服务器IP>:11001/apidocs
- 如果前面还有 Nginx 反向代理并加了前缀(比如 /prod-api ),则一般是:
- http://<域名或IP>/prod-api/apidocs
如果你现在已经在本机运行了 python manage.py ,直接在浏览器里打开 http://localhost:11001/apidocs 试一下即可。