-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
82 lines (64 loc) · 2.03 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
app
"""
from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
# from redis import Redis
app = Flask(__name__)
# redis = Redis(host='localhost', port=6379)
# /// = relative path, //// = absolute path
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class Todo(db.Model): # pylint: disable=too-few-public-methods
"""A dummy docstring."""
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100))
complete = db.Column(db.Boolean)
def pub1(self):
"""A dummy docstring."""
print("")
def pub2(self):
"""A dummy docstring."""
print("")
@app.route("/edit")
def home1():
"""A dummy docstring."""
todo_list = Todo.query.all()
# hit2 = redis.incr('hit2')
return render_template("base.html", todo_list=todo_list)
@app.route("/")
def list1():
"""A dummy docstring."""
todo_list = Todo.query.all()
# hits = redis.incr('hits')
return render_template("list.html", todo_list=todo_list)
@app.route("/add", methods=["POST"])
def add():
"""A dummy docstring."""
title = request.form.get("title")
new_todo = Todo(title=title, complete=False)
db.session.add(new_todo)
db.session.commit()
return redirect(url_for("home1"))
@app.route("/update/<int:todo_id>")
def update(todo_id):
"""A dummy docstring."""
todo = Todo.query.filter_by(id=todo_id).first()
todo.complete = not todo.complete
db.session.commit()
return redirect(url_for("home1"))
@app.route("/delete/<int:todo_id>")
def delete(todo_id):
"""A dummy docstring."""
todo = Todo.query.filter_by(id=todo_id).first()
db.session.delete(todo)
db.session.commit()
return redirect(url_for("home1"))
# @app.route('/')
# def hello():
# redis.incr('hits')
# return 'This Compose/Flask demo has been viewed %s time(s).' % redis.get('hits')
if __name__ == "__main__":
db.create_all()
app.run(debug=True)