This action will force synchronization from shao1chuan/pythonbook, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
from pydantic import BaseModelimport randomfrom fastapi.responses import JSONResponse, FileResponse # 导入FileResponsefrom fastapi import FastAPIfrom fastapi.middleware.cors import CORSMiddleware # 导入CORS中间件from fastapi.responses import FileResponse # 用于返回文件响应import uvicornapp = FastAPI()app.add_middleware(CORSMiddleware,allow_origins=["*"],allow_credentials=True,allow_methods=["*"],allow_headers=["*"],)class Item(BaseModel):x: floaty: floatz: float@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.run(app, host="127.0.0.1", port=8000, log_level="info")if __name__ == "__main__":main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。