I installed FASTAPI and was running below mentioned code
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
and am getting below mentioned error in console on executing the file
(venv) D:\FASTAPI>uvicorn main:app --reload
INFO: Will watch for changes in these directories: ['D:\\FASTAPI']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [7900] using watchgod
ERROR: Error loading ASGI app. Attribute "app" not found in module "main".
I really appreciate any recommendations or suggestions
Suggestion: Make sure you have set VS Studio Code to "autosave". If updated code not saved, interpreter will not allow app startup.
First look the project tree. The main.py file is under app directory.
In my project like this:
fastapi
-> app
-> main.py

Copy codes to main.py:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
Run the server:
uvicorn app.main:app --reload
But if you try to run this server like:
uvicorn main:app --reload
This will cause the error:
Error loading ASGI app. Attribute "app" not found in module "main"
Hope you understood. Run and enjoy coding....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With