-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.py
75 lines (53 loc) · 2.24 KB
/
routes.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python
from flask import Flask, render_template, request, flash
import os
from forms import WeightForm, ConfirmForm
app = Flask(__name__, static_url_path='')
app.secret_key = 'development key'
@app.route('/')
def home():
return render_template('home.html')
return app.send_static_file('main.css')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/control', methods =['GET', 'POST'])
def control():
form = WeightForm(request.form)
if request.method == 'POST':
if form.validate() == False:
#print form.errors
#flash('All fields are required.')
return render_template('control.html', form=form)
else:
weight = str(form.name.data)
weightfile = open('weightfile', 'w')
weightfile.write(weight)
weightfile.close()
form = ConfirmForm(request.form)
return render_template('control2.html', form=form, weight=weight)
elif request.method == 'GET':
return render_template('control.html', form=form)
@app.route('/control2', methods =['GET', 'POST'])
def control2():
form =ConfirmForm(request.form)
file = open('weightfile', 'r')
weight = file.read()
file.close()
if request.method == 'POST':
if form.validate() == False:
print form.errors
flash('All fields are required.')
return render_template('control2.html', form=form, weight=weight)
else:
x = str(form.confirm.data)
if x == '2':
form = WeightForm(request.form)
return render_template('control.html', form=form, weight=weight)
elif x == '1':
return render_template('control2.html', form=form, weight=weight)
elif request.method == 'GET':
print "hello"
return render_template('control.html', form=form, weight = weight)
if __name__ == '__main__':
app.run(host= '0.0.0.0', debug=True)