-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbmi.py
More file actions
36 lines (28 loc) · 1015 Bytes
/
bmi.py
File metadata and controls
36 lines (28 loc) · 1015 Bytes
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
from flask import Flask, render_template, request
import os
app = Flask(__name__)
# # this is the ROOT route
# @app.route('/', methods=['GET'])
# def index():
# return render_template('bmi.html')
# @app.route('/', methods=['POST'])
# def calculate_bmi():
# weight = float(request.form.get('weight'))
# height = float(request.form.get('height'))
# bmi = weight / (height * height)
# return render_template('bmi.html', bmi=bmi)
@app.route('/', methods=['GET', 'POST'])
def calculate_bmi():
if request.method == 'POST':
weight = float(request.form.get('weight'))
height = float(request.form.get('height'))
bmi = weight / (height * height)
return render_template('bmi.html', bmi=bmi)
else:
# GET case: return the template normally
return render_template('bmi.html')
# "magic code" -- boilerplate
if __name__ == '__main__':
app.run(host=os.environ.get('IP'),
port=int(os.environ.get('PORT')),
debug=True)