Reputation: 393
I followed https://fastapi.tiangolo.com/tutorial/bigger-applications/ resource to design my app
.....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")
imported everything properly. When i run uvicorn main:app --reload it is showing "NO attribures 'routes' " error I am not able to find, what is the mistake i am doing here. Could any one helps me.
Upvotes: 2
Views: 4069
Reputation: 118
Also if you have issue with @router not existing make sure you define the APIRouter as router and not web_router = APIRouter()
Upvotes: 0
Reputation: 22449
It seems you're injecting the entire urls module in your last line;
app.include_router(game_urls, prefix="/games")
^
I believe you should only inject the router object, e.g. (you might want to import just the router here instead)
app.include_router(game_urls.router, prefix="/games")
Upvotes: 6