侧边栏壁纸
  • 累计撰写 75 篇文章
  • 累计创建 41 个标签
  • 累计收到 3 条评论

目 录CONTENT

文章目录

PyCharm Python FastAPI 调试及接口按文件分

勤为径苦作舟
2023-11-01 / 0 评论 / 0 点赞 / 16 阅读 / 805 字 / 正在检测是否收录...

接口按文件分

routers/articles.py

from fastapi import APIRouter

router = APIRouter(
  prefix='/articles',
  tags=['articles']
)


@router.get('/')
async def list_articles():
  return []

main.py

import uvicorn
from fastapi import FastAPI

from routers import articles

app = FastAPI()
app.include_router(articles.router)

@app.get('/')
async def root():
  return 'hello'

if __name__ == '__main__':
  uvicorn.run(app, host='0.0.0.0', port=8000, reload=True)

Pycharm 添加 FastAPI

Pycharm 运行/调试配置中添加 FastAPI,选择main.py,确定后用它调试运行,就能进断点了。

0

评论区