-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebapp.py
More file actions
46 lines (35 loc) · 1.33 KB
/
webapp.py
File metadata and controls
46 lines (35 loc) · 1.33 KB
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
from flask import Flask,render_template, request
from flask_sqlalchemy import SQLAlchemy
from send_email import send_email
app=Flask(__name__)
#Update the username and password of the URL and the databasename
#'postgresql://username:password!@endpointURL:port/databasename'
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://username:password!@flaskpythonapp.cwyt1tt0eioi.us-east-1.rds.amazonaws.com:5432/databasename'
db=SQLAlchemy(app)
class Data(db.Model):
__tablename__="flaskTable"
id=db.Column(db.Integer,primary_key=True)
email=db.Column(db.String(120),unique=True)
height=db.Column(db.Integer)
def __init__(self,email_,height_):
self.email=email_
self.height=height_
db.create_all()
@app.route("/")
def home():
return render_template("index.html")
@app.route("/success",methods=['POST'])
def success():
if request.method=='POST':
email=request.form["email_name"]
height=request.form["height"]
send_email(email,height)
data=Data(email,height)
if db.session.query(Data).filter(Data.email==email).count()==0:
db.session.add(data)
db.session.commit()
return render_template("success.html")
return render_template("index.html",text="Email already exists")
if __name__=='__main__':
app.debug=True
app.run()