Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from flask import Flask, redirect, render_template, url_for
- from flaskext.sqlalchemy import SQLAlchemy
- from flaskext.wtf import Form, SubmitField, TextField, email, required
- # Application, settings and db connection
- app = Flask(__name__)
- app.config['DEBUG'] = True
- app.config['SECRET_KEY'] = 'secret'
- app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////data/db/oktoberfestplatz.db'
- db = SQLAlchemy(app)
- # Models
- class EmailAddress(db.Model):
- id = db.Column(db.Integer, primary_key = True)
- email = db.Column(db.String(120), unique = True)
- def __init__(self, email):
- self.email = email
- # Forms
- class NewsletterSubscription(Form):
- email = TextField('Email address', validators = [email(), required()])
- # Views
- @app.route('/', methods=['GET', 'POST'])
- def index():
- form = NewsletterSubscription()
- if form.validate_on_submit():
- email = EmailAddress(form.email.data)
- db.session.add(email)
- db.session.commit()
- return redirect(url_for('subscribed'))
- return render_template('index.html', form=form)
- @app.route('/subscribed')
- def subscribed():
- return render_template('subscribed.html')
- if __name__ == '__main__':
- app.run()
Add Comment
Please, Sign In to add comment