[Python] Cannot access any endpoint apart from localhost in Python FastAPI

Discussão em 'Python' iniciado por Stack, Março 18, 2025.

  1. Stack

    Stack Membro Participativo

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

    I have written the 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


    [​IMG]

    Continue reading...

Compartilhe esta Página