12345678910111213141516171819202122232425262728293031323334 |
- from typing import Optional
- from fastapi import FastAPI
- from pydantic import BaseModel
- from fastapi.staticfiles import StaticFiles
- app = FastAPI()
- app.mount("/static", StaticFiles(directory="static"), name="static")
- class Item(BaseModel):
- name: str
- price: float
- is_offer: Optional[bool] = None
- @app.get("/")
- def read_root():
- return {"Hello": "World"}
- @app.get("/items/{item_id}")
- def read_item(item_id: int, q: Optional[str] = None):
- return {"item_id": item_id, "q": q}
- @app.post("/enter_invite_code")
- def update_item(item_id: int, item: Item):
- db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
- return {"item_name": item.name, "item_id": item_id}
|