-
Notifications
You must be signed in to change notification settings - Fork 14
/
app.py
32 lines (25 loc) · 896 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from flask import Flask, render_template
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = \
'postgres://vagrant:password@192.168.100.20/vagrant_ansible_tutorial'
db = SQLAlchemy(app)
class AppUser(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True)
email = db.Column(db.String(120), unique=True)
def __init__(self, username, email):
self.username = username
self.email = email
@app.route('/')
def index():
return render_template('index.html', users=AppUser.query.all())
@app.before_first_request
def invalidate_data():
db.drop_all()
db.create_all()
for u, e in [('matt', 'matt@nobien.net'),
('marc', 'marc@nobien.net')]:
db.session.add(AppUser(u, e))
db.session.commit()