generated from nogibjj/fanxu_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
39 lines (30 loc) · 960 Bytes
/
app.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
from flask import Flask, redirect, url_for, request, render_template_string
import requests
app = Flask(__name__)
url = "https://zenquotes.io/api/random"
template = """
<!DOCTYPE html>
<html>
<body>
<h1>Quote Generator</h1>
<form method = "POST" action = "/">
<p>Enter Name:</p>
<p><input type = "text" name = "nm" /></p>
<p><input type = "submit" value = "submit" /></p>
</form>
</body>
</html>
"""
@app.route("/success/<name>")
def success(name):
response = requests.get(url)
print(response.text)
return f'Hi {name}, your quote is "{response.json()[0]["q"]}" - {response.json()[0]["a"]}'
@app.route("/", methods=["POST", "GET"])
def login():
if request.method == "POST":
user = request.form["nm"]
return redirect(url_for("success", name=user))
return render_template_string(template)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)