-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkoutapp.py
38 lines (32 loc) · 968 Bytes
/
workoutapp.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
import sqlite3
from flask import Flask, render_template, request
with sqlite3.connect("meal.db") as connection:
c = connection.cursor()
try:
c.execute("""CREATE TABLE meals
(names TEXT, foods TEXT, drinks TEXT)
""")
except:
pass
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
info = []
if request.method == 'POST' and 'name' in request.form:
name = request.form.get('name')
food = request.form.get('food')
drink = request.form.get('drink')
for i in (name, food, drink):
info.append(i)
with sqlite3.connect("meal.db") as connection:
c = connection.cursor()
c.execute("INSERT INTO meals VALUES(?, ?, ?)", info)
return render_template('last_meal.html',
info=info)
@app.route('/meal_history')
def meal_history():
with sqlite3.connect("meal.db") as connection:
c = connection.cursor()
return render_template('meal_history.html',
c=c)
app.run()