Adding WTForms to validate basic form input
This commit is contained in:
parent
0e7b589858
commit
5c9415cf6f
|
@ -3,3 +3,4 @@ cryptography
|
||||||
flask
|
flask
|
||||||
gunicorn
|
gunicorn
|
||||||
ldap3
|
ldap3
|
||||||
|
wtforms
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
import logging
|
import logging
|
||||||
from flask import Flask, render_template
|
from flask import Flask, render_template
|
||||||
|
from forms import UserLookupForm
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.logger.setLevel(logging.INFO)
|
app.logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return render_template('landing.html')
|
if request.method == 'POST':
|
||||||
|
form = UserLookupForm(request.form)
|
||||||
|
if form.validate():
|
||||||
|
email = form.email.data
|
||||||
|
else:
|
||||||
|
app.logger.warn('Form validation failed')
|
||||||
|
else:
|
||||||
|
form = UserLookupForm(request.args)
|
||||||
|
|
||||||
|
return render_template('landing.html', form=form)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
from wtforms import Form, StringField, validators
|
||||||
|
|
||||||
|
class UserLookupForm(Form):
|
||||||
|
email = StringField('Email Address', [validators.Email()])
|
|
@ -4,5 +4,12 @@
|
||||||
<h1>FileDrop App</h1>
|
<h1>FileDrop App</h1>
|
||||||
<div>
|
<div>
|
||||||
Form to select and upload files will go here.
|
Form to select and upload files will go here.
|
||||||
|
<form method="POST">
|
||||||
|
<dl>
|
||||||
|
<dt>{{ form.email.label }}</dt>
|
||||||
|
<dd>{{ form.email()|safe }}</dd>
|
||||||
|
</dl>
|
||||||
|
<button type="submit">Next</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue