first version

Alex Moreau 1 year ago
commit fe518f3dce13ecb271345084df227f29e419081a
3 changed files with 36 additions and 0 deletions
+17-0app.py ADDED
View File
@@ -0,0 +1,17 @@
1+from flask import Flask, redirect, render_template, request
2+
3+app = Flask(__name__)
4+todos = []
5+
6+
7+@app.route("/")
8+def index():
9+ return render_template("index.html", todos=todos)
10+
11+
12+@app.post("/add")
13+def add():
14+ title = request.form.get("title", "").strip()
15+ if title:
16+ todos.append({"title": title, "done": False})
17+ return redirect("/")
+1-0requirements.txt ADDED
View File
@@ -0,0 +1 @@
1+flask==3.0.3
+18-0templates/index.html ADDED
View File
@@ -0,0 +1,18 @@
1+<!doctype html>
2+<html lang="en">
3+<head>
4+ <meta charset="utf-8">
5+ <title>Todo</title>
6+ <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
7+</head>
8+<body>
9+ <h1>My todos</h1>
10+ <form action="/add" method="post"><input name="title"><button>Add</button></form>
11+ <ul>
12+ {% for t in todos %}
13+ <li class="{{ 'done' if t.done }}">{{ t.title }}
14+ <form action="/done/{{ loop.index0 }}" method="post"><button>✓</button></form></li>
15+ {% endfor %}
16+ </ul>
17+</body>
18+</html>