From 4ea8f92ed382e6d084b884ef0d4f6ee13abeb69b Mon Sep 17 00:00:00 2001 From: Alexander Hosking Date: Tue, 20 Dec 2016 01:50:26 -0500 Subject: [PATCH] Further progress with forms --- influx_frontend.py | 31 +++++++++++++++++++++++++------ templates/index.html | 11 +++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 templates/index.html diff --git a/influx_frontend.py b/influx_frontend.py index fe89464..2ce3559 100644 --- a/influx_frontend.py +++ b/influx_frontend.py @@ -1,16 +1,35 @@ -from flask import Flask +from flask import Flask, render_template +from flask_wtf import FlaskForm +from wtforms import StringField +from wtforms.validators import DataRequired + +from flask_wtf.csrf import CsrfProtect + +csrf = CsrfProtect() +WTF_CSRF_SECRET_KEY = 'a random string' + app = Flask(__name__) +app.secret_key = 'The key to life' +csrf.init_app(app) from influxdb import InfluxDBClient def db_main(host='localhost', port=8086): user = 'root' password = 'root' dbname = 'gas' - -@app.route('/') +class influx_form(FlaskForm): + name = StringField('name', validators=[DataRequired()]) + + +@app.route('/success') +def success(): + return "Form success!" + +@app.route('/', methods=('GET', 'POST')) def main_page(): - - return 'Hello influxers!' - + form = influx_form() + if form.validate_on_submit(): + return redirect('/success') + return render_template('index.html', form=form) app.run(debug=True) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..989b4c5 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,11 @@ + + +Influx Front-End + + +
+ {{ form.name.label }} {{ form.name(size=20) }} + +
+ +