-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
54 lines (44 loc) · 1.26 KB
/
Copy pathapp.py
File metadata and controls
54 lines (44 loc) · 1.26 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from flask import Flask, render_template, request, redirect, url_for
import random
app = Flask(__name__)
todos = [
{
'id': 1,
'name': 'Write SQL',
'checked': False,
},
{
'id': 2,
'name': 'Write Python',
'checked': True,
},
]
@app.route("/", methods=["GET", "POST"])
@app.route("/home" , methods=["GET" , "POST"])
def home():
if (request.method == "POST"):
todo_name = request.form["todo_name"]
cur_id = random.randint(1, 1000)
todos.append({
'id': cur_id,
'name': todo_name,
'checked': False,
})
return render_template("index.html" , items=todos)
@app.route("/checked/<int:todo_id>",methods=["POST"])
def check_todo(todo_id):
for todo in todos:
if todo['id'] == todo_id:
todo['checked'] = not todo['checked']
break
return redirect(url_for('home'))
@app.route("/delete/<int:todo_id>",methods=["POST"])
def delete_todo(todo_id):
for todo in todos:
if todo['id'] == todo_id:
todos.remove(todo)
return redirect(url_for('home'))
if __name__ == "__main__":
import os
debug_mode = os.environ.get("FLASK_DEBUG", "1") == "1"
app.run(debug=debug_mode, port=5000)