使用此文件夹结构和配置,其中 main 位于父目录中

启动.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: FastAPI",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": [
"main:app"
],
"jinja": true
}
]
}
主文件
from fastapi import FastAPI
app = FastAPI(
title="test",
description="test",
version="0.0.1",
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main:app",
host="0.0.0.0",
reload=True,
port=3001,
)