pythonbook/实例学习 nicegui/fastapi/fastapi_nicegui.py

29 lines
611 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from fastapi import FastAPI
import uvicorn
from nicegui import ui
app = FastAPI()
def fastapi(app:FastAPI):
@app.get('/')
def read_root():
return {'Hello': 'World'}
fastapi(app)
def nicegui(app: FastAPI) -> None:
@ui.page('/a')
def a():
ui.label("this is aaaaaaaaaaaaaaa")
@ui.page('/b')
def b():
ui.label("this is bbbbbbbbbbbbbbbbbbb")
ui.run_with(app)
nicegui(app)
def main():
# 使用uvicorn运行FastAPI应用指定主机地址和端口
uvicorn.run(app, host="127.0.0.1", port=8000, log_level="info")
if __name__ == "__main__":
main()