- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
Latest commit
34 lines (32 loc) · 1 KB
/
Copy pathapp.py
File metadata and controls
34 lines (32 loc) · 1 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
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 14 21:21:36 2021
@author: 938306
"""
fromflaskimportFlask,render_template,request
fromdatetimeimportdatetime
fromflask_sqlalchemyimportSQLAlchemy
app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']="sqlite:///my.db"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=False
db=SQLAlchemy(app)
classMy(db.Model):
sno=db.Column(db.Integer,primary_key=True)
email=db.Column(db.String(20),nullable=False )
name=db.Column(db.String(20),nullable=False)
date_create=db.Column(db.DateTime, default=datetime.utcnow)
def__repr__(self)->str:
returnf"{self.sno}-{self.email}"
@app.route('/',methods=['GET','POST'])
defhome():
ifrequest.method=="POST":
email=request.form['Email']
name=request.form['name']
my=My(email=email,name=name)
db.session.add(my)
db.session.commit()
allmy=My.query.all()
returnrender_template("index.html",allmy=allmy)
if__name__=="__main__":
app.debug=True
app.run(host='localhost')