Adding WTForms to validate basic form input

This commit is contained in:
Alex Wright 2018-11-17 09:40:29 +01:00
parent 0e7b589858
commit 5c9415cf6f
4 changed files with 23 additions and 1 deletions

View File

@ -3,3 +3,4 @@ cryptography
flask flask
gunicorn gunicorn
ldap3 ldap3
wtforms

View File

@ -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)

4
backend/src/forms.py Normal file
View File

@ -0,0 +1,4 @@
from wtforms import Form, StringField, validators
class UserLookupForm(Form):
email = StringField('Email Address', [validators.Email()])

View File

@ -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 %}