-
Notifications
You must be signed in to change notification settings - Fork 49
/
app.py
33 lines (25 loc) · 849 Bytes
/
app.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
import datetime
import os
from flask import Flask, render_template, redirect, url_for
from forms import ItemForm
from models import Items
from database import db_session
app = Flask(__name__)
app.secret_key = os.environ['APP_SECRET_KEY']
@app.route("/", methods=('GET', 'POST'))
def add_item():
form = ItemForm()
if form.validate_on_submit():
item = Items(name=form.name.data, quantity=form.quantity.data, description=form.description.data, date_added=datetime.datetime.now())
db_session.add(item)
db_session.commit()
return redirect(url_for('success'))
return render_template('index.html', form=form)
@app.route("/success")
def success():
results = []
qry = db_session.query(Items)
results = qry.all()
return str(results)
if __name__ == '__main__':
app.run(host='0.0.0.0')