Guest User

Untitled

a guest
Jan 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. from flask import Flask, redirect, render_template, url_for
  4. from flaskext.sqlalchemy import SQLAlchemy
  5. from flaskext.wtf import Form, SubmitField, TextField, email, required
  6.  
  7. # Application, settings and db connection
  8. app = Flask(__name__)
  9.  
  10. app.config['DEBUG'] = True
  11. app.config['SECRET_KEY'] = 'secret'
  12. app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////data/db/oktoberfestplatz.db'
  13.  
  14. db = SQLAlchemy(app)
  15.  
  16. # Models
  17. class EmailAddress(db.Model):
  18.  
  19. id = db.Column(db.Integer, primary_key = True)
  20. email = db.Column(db.String(120), unique = True)
  21.  
  22. def __init__(self, email):
  23. self.email = email
  24.  
  25.  
  26. # Forms
  27. class NewsletterSubscription(Form):
  28.  
  29. email = TextField('Email address', validators = [email(), required()])
  30.  
  31.  
  32. # Views
  33. @app.route('/', methods=['GET', 'POST'])
  34. def index():
  35. form = NewsletterSubscription()
  36. if form.validate_on_submit():
  37. email = EmailAddress(form.email.data)
  38. db.session.add(email)
  39. db.session.commit()
  40. return redirect(url_for('subscribed'))
  41. return render_template('index.html', form=form)
  42.  
  43. @app.route('/subscribed')
  44. def subscribed():
  45. return render_template('subscribed.html')
  46.  
  47.  
  48. if __name__ == '__main__':
  49. app.run()
Add Comment
Please, Sign In to add comment