Further progress with forms

This commit is contained in:
Alexander Hosking 2016-12-20 01:50:26 -05:00
parent 2304175f46
commit 4ea8f92ed3
2 changed files with 36 additions and 6 deletions

View File

@ -1,5 +1,16 @@
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 = Flask(__name__)
app.secret_key = 'The key to life'
csrf.init_app(app)
from influxdb import InfluxDBClient from influxdb import InfluxDBClient
def db_main(host='localhost', port=8086): def db_main(host='localhost', port=8086):
@ -7,10 +18,18 @@ def db_main(host='localhost', port=8086):
password = 'root' password = 'root'
dbname = 'gas' dbname = 'gas'
class influx_form(FlaskForm):
name = StringField('name', validators=[DataRequired()])
@app.route('/')
@app.route('/success')
def success():
return "Form success!"
@app.route('/', methods=('GET', 'POST'))
def main_page(): def main_page():
form = influx_form()
return 'Hello influxers!' if form.validate_on_submit():
return redirect('/success')
return render_template('index.html', form=form)
app.run(debug=True) app.run(debug=True)

11
templates/index.html Normal file
View File

@ -0,0 +1,11 @@
<html>
<head>
Influx Front-End
</head>
<body>
<form method="POST" action="/">
{{ form.name.label }} {{ form.name(size=20) }}
<input type="submit" value="Go">
</form>
</body>
</html>