I created a tool in flask, but want to move it to fastapi. I defined two routes as follows:
from fastapi import FastAPI, Request, Form
from fastapi.templating import Jinja2Templates
from fastapi.responses import HTMLResponse
@app.get("/mytool")
async def home(request: Request, response_class=HTMLResponse):
# displays tool
return templates.TemplateResponse("index_tool.html", {"request": request})
@app.post("/mytool")
async def home(request: Request,
var1: str = Form(),
var2: str = Form(),
var3: int = Form(),
var4: int = Form()):
# ... perform calculation
result = myCalculation(var1, var2, var3, var4)
return templates.TemplateResponse("index_tool.html", {"request": request,
"result": result})
However, whenever I submit the form. It gives the error POST / HTTP/1.1" 405 Method Not Allowed, even though I defined both the GET and POST route. How should I go about creating such a tool?