forked from rasbt/python-machine-learning-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
31 lines (25 loc) · 936 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
from flask import Flask, render_template, request
from wtforms import Form, DecimalField, validators
app = Flask(__name__)
class EntryForm(Form):
x_entry = DecimalField('x:',
places=10,
validators=[validators.NumberRange(-1e10, 1e10)])
y_entry = DecimalField('y:',
places=10,
validators=[validators.NumberRange(-1e10, 1e10)])
@app.route('/')
def index():
form = EntryForm(request.form)
return render_template('entry.html', form=form, z='')
@app.route('/results', methods=['POST'])
def results():
form = EntryForm(request.form)
z = ''
if request.method == 'POST' and form.validate():
x = request.form['x_entry']
y = request.form['y_entry']
z = float(x) + float(y)
return render_template('entry.html', form=form, z=z)
if __name__ == '__main__':
app.run(debug=True)