-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
48 lines (42 loc) · 1.22 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from fastapi import FastAPI, Form
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
app = FastAPI()
# 静的ファイルの提供
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/", response_class=HTMLResponse)
async def get_form(name: str = ""):
return f"""
<html>
<body>
<h1>GETリクエスト</h1>
<p>名前: {name}</p>
<a href="/static/index.html">戻る</a>
</body>
</html>
"""
@app.post("/", response_class=HTMLResponse)
async def post_form(name: str = Form(...)):
return f"""
<html>
<body>
<h1>POSTリクエスト</h1>
<p>名前: {name}</p>
<a href="/static/index.html">戻る</a>
</body>
</html>
"""
@app.post("/password", response_class=HTMLResponse)
async def post_pw_form(password: str = Form(...)):
return f"""
<html>
<body>
<h1>パスワード</h1>
<p>あなたのパスワードは: {password} です</p>
<a href="/static/index.html">戻る</a>
</body>
</html>
"""
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)