forked from inkjet/flask-aws-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
51 lines (42 loc) · 1.71 KB
/
application.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'''
Simple Flask application to test deployment to Amazon Web Services
Uses Elastic Beanstalk and RDS
Author: Scott Rodkey - [email protected]
Step-by-step tutorial: https://medium.com/@rodkey/deploying-a-flask-application-on-aws-a72daba6bb80
'''
from flask import Flask, render_template, request
from application import db
from application.models import Data
from application.forms import EnterDBInfo, RetrieveDBInfo
# Elastic Beanstalk initalization
application = Flask(__name__)
application.debug=True
# change this to your own value
application.secret_key = 'cC1YCIWOj9GgWspgNEo2'
@application.route('/', methods=['GET', 'POST'])
@application.route('/index', methods=['GET', 'POST'])
def index():
form1 = EnterDBInfo(request.form)
form2 = RetrieveDBInfo(request.form)
if request.method == 'POST' and form1.validate():
data_entered = Data(notes=form1.dbNotes.data)
try:
db.session.add(data_entered)
db.session.commit()
db.session.close()
except:
db.session.rollback()
return render_template('thanks.html', notes=form1.dbNotes.data)
if request.method == 'POST' and form2.validate():
try:
num_return = int(form2.numRetrieve.data)
query_db = Data.query.order_by(Data.id.desc()).limit(num_return)
for q in query_db:
print(q.notes)
db.session.close()
except:
db.session.rollback()
return render_template('results.html', results=query_db, num_return=num_return)
return render_template('index.html', form1=form1, form2=form2)
if __name__ == '__main__':
application.run(host='0.0.0.0')