-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathapp.py
47 lines (32 loc) · 1.24 KB
/
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
40
41
42
43
44
45
46
47
from flask import render_template, request
from keep_alive import keep_alive, app
@app.route("/")
def main():
return render_template("calculator.html")
@app.route("/calculate", methods=["POST"])
def calculate():
number_one = request.form["number_one"]
number_two = request.form["number_two"]
operation = request.form["operation"]
if operation == "add":
result = float(number_one) + float(number_two)
return render_template("calculator.html", result=result)
elif operation == "subtract":
result = float(number_one) - float(number_two)
return render_template("calculator.html", result=result)
elif operation == "multiply":
result = float(number_one) * float(number_two)
return render_template("calculator.html", result=result)
elif operation == "divide":
result = float(number_one) / float(number_two)
return render_template("calculator.html", result=result)
else:
return render_template("calculator.html")
@app.errorhandler(404)
def not_found(error):
return render_template("404.html", error=error)
@app.errorhandler(500)
def server_error(error):
return render_template("500.html", error=error)
if __name__ == "__main__":
keep_alive()