-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.py
41 lines (31 loc) · 1.02 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
from flask import Flask, render_template, request, flash
from forms import ContactForm
from flask_wtf import Form
from wtforms import StringField, TextAreaField, SubmitField
app = Flask(__name__)
app.secret_key = 'development key'
@app.route("/")
def home():
return render_template('home.html')
@app.route('/test', methods=['GET', 'POST'])
def test():
class F(Form):
submit = SubmitField("Submit")
pass
field_list = ['foo', 'bar', 'qux']
for name in field_list:
setattr(F, name, StringField(name))
form = F()
if request.method == 'POST':
return 'Form posted'
elif request.method == 'GET':
return render_template('test.html', form=form, field_names=field_list)
@app.route('/test2', methods=['GET', 'POST'])
def test2():
form = ContactForm()
if request.method == 'POST':
return 'Form posted'
elif request.method == 'GET':
return render_template('test2.html', form=form)
if __name__ == "__main__":
app.run(debug=True, use_reloader=True)