first version
commit 19a6771d04239f4a61e4246f96b8cec68d9364cc
3 changed files with 36 additions and 0 deletions
app.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("/") | |
requirements.txt ADDED
View File
| @@ -0,0 +1 @@ | ||
| 1 | +flask==3.0.3 | |
templates/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> | |