接口按文件分
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
,确定后用它调试运行,就能进断点了。
评论区