From 486abc09c92f94d0eb21ad83db614ea1224fd4e1 Mon Sep 17 00:00:00 2001 From: aiolishi Date: Wed, 13 Mar 2024 09:13:30 +0800 Subject: [PATCH] shao --- fastapi_plotly/index2.html | 61 ++++++++++++++++++++++++++++++++++++++ fastapi_plotly/main.py | 19 +++++++----- 2 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 fastapi_plotly/index2.html diff --git a/fastapi_plotly/index2.html b/fastapi_plotly/index2.html new file mode 100644 index 0000000..f8f7d3a --- /dev/null +++ b/fastapi_plotly/index2.html @@ -0,0 +1,61 @@ + + + + + 3D Scatter Plot with Input + + + + +
+ + + + +
+
+ + + diff --git a/fastapi_plotly/main.py b/fastapi_plotly/main.py index e9f0bb5..c50f444 100644 --- a/fastapi_plotly/main.py +++ b/fastapi_plotly/main.py @@ -10,13 +10,12 @@ import uvicorn app = FastAPI() -# CORS中间件的设置 app.add_middleware( CORSMiddleware, - allow_origins=["*"], # 允许所有源 + allow_origins=["*"], allow_credentials=True, - allow_methods=["*"], # 允许所有方法 - allow_headers=["*"], # 允许所有头部 + allow_methods=["*"], + allow_headers=["*"], ) class Item(BaseModel): @@ -24,17 +23,21 @@ class Item(BaseModel): y: float z: float -@app.get("/data") -async def get_data(): - return JSONResponse(content={"x": random.random(), "y": random.random(), "z": random.random()}) +@app.post("/data") +async def post_data(item: Item): + # 这里可以对item进行任何需要的处理 + return item @app.get("/") async def get_index(): # 直接返回同目录下的index.html文件 return FileResponse('index.html') +@app.get("/2") +async def get_index(): + # 直接返回同目录下的index.html文件 + return FileResponse('index2.html') def main(): - # 使用uvicorn运行FastAPI应用,指定主机地址和端口 uvicorn.run(app, host="127.0.0.1", port=8000, log_level="info") if __name__ == "__main__":