]> git.angelumana.com Git - wu-api/.git/commitdiff
add basic fastapi site
authoribidyouadu <angel.d.umana@gmail.com>
Fri, 19 Jul 2024 03:23:56 +0000 (22:23 -0500)
committeribidyouadu <angel.d.umana@gmail.com>
Fri, 19 Jul 2024 03:23:56 +0000 (22:23 -0500)
app/main.py [new file with mode: 0644]
app/templates/index.html [new file with mode: 0644]
app/templates/result.html [new file with mode: 0644]

diff --git a/app/main.py b/app/main.py
new file mode 100644 (file)
index 0000000..1a5cb0f
--- /dev/null
@@ -0,0 +1,26 @@
+from fastapi import FastAPI, Request, Form
+from fastapi.responses import HTMLResponse
+from fastapi.templating import Jinja2Templates
+
+app = FastAPI()
+templates = Jinja2Templates("templates")
+
+@app.get("/", response_class=HTMLResponse)
+def index(request: Request):
+    context = {"request": request}
+    response = templates.TemplateResponse("index.html", context)
+    
+    return response
+
+@app.post("/transforminate")
+def transforminate(request: Request, favnum: float = Form(...)):
+    output = favnum/3.14159
+    context = {"request": request, "output": output}
+    response = templates.TemplateResponse("result.html", context)
+
+    return response
+
+if __name__ == "__main__":
+    import uvicorn
+    
+    uvicorn.run(app, host="localhost", port=8001)
\ No newline at end of file
diff --git a/app/templates/index.html b/app/templates/index.html
new file mode 100644 (file)
index 0000000..334ae4e
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html><body>
+    <p>Plug in your favorite number and we'll pass it through the useless number transforminator</p>
+    <form action="/transforminate" method="post">
+        <label for="favnum">Your fav number:</label>
+        <input type="number" id="favnum" name="favnum" required>
+        <button type="submit">transforminate!</button>
+    </form>
+</body></html>
\ No newline at end of file
diff --git a/app/templates/result.html b/app/templates/result.html
new file mode 100644 (file)
index 0000000..92222e0
--- /dev/null
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+<html><body>
+    <p>Behold! Your useless number transforimnator-inated number is {{output}} !</p>
+    <a href="/">Do it again, do it again!</a>
+</body></html>
\ No newline at end of file