main.py
app = FastAPI()
crud.py
from main import app
@app.get("/posts")
async def posts():
return {"posts": 'test'}
python uvicorn main:app --reload
I cant' access '/posts'
You're trying to return posts, but posts is the name of the function...
You're trying to return
posts, butpostsis the name of the function...
I updated, so, I can't access /posts
Your application is not able to "see" the crud.py. Maybe you can add the crud.py into your __init__.py and it will solve the problem, or...
Suggestion:
# main.py
from fastapi import FastAPI
from .crud import router
app = FastAPI()
app.include_router(router)
# crud.py
from fastapi import APIRouter
router = APIRouter()
@router.get("/posts")
async def posts():
return {"posts": 'test'}
Thanks for the help here @Kludex ! :clap: :bow:
Thanks for reporting back and closing the issue :+1: