-
Notifications
You must be signed in to change notification settings - Fork 54
/
app_run.py
41 lines (34 loc) · 1.09 KB
/
app_run.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
from flask import *
from datetime import datetime
from dbModel import *
app = Flask(__name__)
@app.route('/')
@app.route('/index')
def index():
data = "Deploying a Flask App To Heroku"
data_UserData = UserData.query.all()
history_dic = {}
history_list = []
for _data in data_UserData:
history_dic['Name'] = _data.Name
history_dic['Id'] = _data.Id
history_dic['Description'] = _data.Description
history_dic['CreateDate'] = _data.CreateDate.strftime('%Y/%m/%d %H:%M:%S')
history_list.append(history_dic)
history_dic = {}
return render_template('index.html', **locals())
@app.route('/API/add_data', methods=['POST'])
def add_data():
name = request.form['name']
description = request.form['description']
if name != "" and description != "":
add_data = UserData(
Name=name,
Description=description,
CreateDate=datetime.now()
)
db.session.add(add_data)
db.session.commit()
return redirect(url_for('index'))
if __name__ == '__main__':
app.run(debug=True)