Home > database >  Cannot access any endpoint apart from localhost in Python FastAPI
Cannot access any endpoint apart from localhost in Python FastAPI

Time:07-26

I am learning to use fastapi on Windows. The problem is that I cannot access any endpoint different than localhost ("/").

I have written a following code in main.py file that is located inside app folder (app folder contains init.py file and main.py file):

from fastapi import FastAPI

app = FastAPI()

my_posts = { 1:{
        "date":"01/01/2022",
        "user":"Matt",
        "type":"photo"
}
}

@app.get("/")
def get_root():
    return{"Hello":"User"} #works fine


@app.get("/post/{post_id}")
def get_post(post_id:int):
    return{"data": my_posts} #doesn't work


enter image description here

  • Related