Not only JS folks can do it we can do it too!
First, install this library:
pip install flaskwebgui
Next add the following code in a main.py
file:
#main.py
from fastapi import FastAPI
from flaskwebgui import FlaskUI # import FlaskUI
app = FastAPI()
ui = FlaskUI(app) # feed app and parameters
@app.get("/")
def read_root():
return {"message": "Works with FastAPI!"}
if __name__ == "__main__":
ui.run()
Alternatively, next to main.py
create a file called gui.py
and add the following contents:
#gui.py
from flaskwebgui import FlaskUI
from main import app
FlaskUI(app, width=600, height=500).run()
Next start the application with:
python main.py
#or
python gui.py #in case you created gui.py
Fastapi will be served by uvicorn
.
And that's all!
Top comments (2)
I'm getting the error
AttributeError: 'FastAPI' object has no attribute 'after_request'
whether I runpython main.py
orpython gui.py
.I have flaskwebgui, flask and fastapi installed ok.
Had to change the startup in both files to
FlaskUI(app, start_server='fastapi', width=600, height=500).run()
Открывается браузер с надписью: не удается открыть эту страницу. И все.