fastapi没有属性'routes'怎么解决?
how to solve no attribute 'routes' in fastapi?
我按照 https://fastapi.tiangolo.com/tutorial/bigger-applications/ 资源设计了我的应用程序
.....game/urls.py....
from fastapi import APIRouter
router = APIRouter()
@router.post("/", response_model=schemas.GameOut, tags=["games"])
def create_game(game: schemas.GameIn, db: Session = Depends(get_db)):
return Crud.create(db,game,model)
...main.py...
from game import urls as game_urls
app.include_router(game_urls,prefix="/games")
已正确导入所有内容。
当我 运行 uvicorn main:app --reload 它显示 "NO attribures 'routes' " 错误
我找不到,我在这里做错了什么。谁能帮帮我
您似乎在最后一行注入了整个 urls 模块;
app.include_router(game_urls, prefix="/games")
^
我相信你应该只注入路由器对象,例如(您可能只想在此处导入路由器)
app.include_router(game_urls.router, prefix="/games")
我按照 https://fastapi.tiangolo.com/tutorial/bigger-applications/ 资源设计了我的应用程序
.....game/urls.py....
from fastapi import APIRouter
router = APIRouter()
@router.post("/", response_model=schemas.GameOut, tags=["games"])
def create_game(game: schemas.GameIn, db: Session = Depends(get_db)):
return Crud.create(db,game,model)
...main.py...
from game import urls as game_urls
app.include_router(game_urls,prefix="/games")
已正确导入所有内容。 当我 运行 uvicorn main:app --reload 它显示 "NO attribures 'routes' " 错误 我找不到,我在这里做错了什么。谁能帮帮我
您似乎在最后一行注入了整个 urls 模块;
app.include_router(game_urls, prefix="/games")
^
我相信你应该只注入路由器对象,例如(您可能只想在此处导入路由器)
app.include_router(game_urls.router, prefix="/games")