Spaces:
Sleeping
Sleeping
AntDX316
commited on
Commit
·
c826ee0
1
Parent(s):
92eddaf
updated
Browse files- project/app.py +26 -0
- project/requirements.txt +2 -0
- project/static/style.css +89 -0
- project/templates/index.html +32 -0
project/app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, redirect, url_for
|
| 2 |
+
|
| 3 |
+
app = Flask(__name__)
|
| 4 |
+
|
| 5 |
+
# Store tasks in memory (would use a database in a real application)
|
| 6 |
+
tasks = []
|
| 7 |
+
|
| 8 |
+
@app.route('/')
|
| 9 |
+
def index():
|
| 10 |
+
return render_template('index.html', tasks=tasks)
|
| 11 |
+
|
| 12 |
+
@app.route('/add', methods=['POST'])
|
| 13 |
+
def add():
|
| 14 |
+
task = request.form.get('task')
|
| 15 |
+
if task:
|
| 16 |
+
tasks.append(task)
|
| 17 |
+
return redirect(url_for('index'))
|
| 18 |
+
|
| 19 |
+
@app.route('/delete/<int:task_id>')
|
| 20 |
+
def delete(task_id):
|
| 21 |
+
if 0 <= task_id < len(tasks):
|
| 22 |
+
tasks.pop(task_id)
|
| 23 |
+
return redirect(url_for('index'))
|
| 24 |
+
|
| 25 |
+
if __name__ == '__main__':
|
| 26 |
+
app.run(debug=True, host='0.0.0.0')
|
project/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask==2.3.3
|
| 2 |
+
Werkzeug==2.3.7
|
project/static/style.css
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
* {
|
| 2 |
+
margin: 0;
|
| 3 |
+
padding: 0;
|
| 4 |
+
box-sizing: border-box;
|
| 5 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
body {
|
| 9 |
+
background-color: #f5f5f5;
|
| 10 |
+
padding: 20px;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
.container {
|
| 14 |
+
max-width: 600px;
|
| 15 |
+
margin: 0 auto;
|
| 16 |
+
background-color: white;
|
| 17 |
+
border-radius: 8px;
|
| 18 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 19 |
+
padding: 20px;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
h1 {
|
| 23 |
+
text-align: center;
|
| 24 |
+
margin-bottom: 20px;
|
| 25 |
+
color: #333;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
.task-form {
|
| 29 |
+
display: flex;
|
| 30 |
+
margin-bottom: 20px;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
.task-form input {
|
| 34 |
+
flex: 1;
|
| 35 |
+
padding: 10px;
|
| 36 |
+
border: 1px solid #ddd;
|
| 37 |
+
border-radius: 4px 0 0 4px;
|
| 38 |
+
font-size: 16px;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.task-form button {
|
| 42 |
+
padding: 10px 15px;
|
| 43 |
+
background-color: #4CAF50;
|
| 44 |
+
color: white;
|
| 45 |
+
border: none;
|
| 46 |
+
border-radius: 0 4px 4px 0;
|
| 47 |
+
cursor: pointer;
|
| 48 |
+
font-size: 16px;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.task-form button:hover {
|
| 52 |
+
background-color: #45a049;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
.task-list {
|
| 56 |
+
list-style-type: none;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.task-list li {
|
| 60 |
+
padding: 10px 15px;
|
| 61 |
+
border-bottom: 1px solid #eee;
|
| 62 |
+
display: flex;
|
| 63 |
+
justify-content: space-between;
|
| 64 |
+
align-items: center;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.task-list li:last-child {
|
| 68 |
+
border-bottom: none;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.task-text {
|
| 72 |
+
flex: 1;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.delete-btn {
|
| 76 |
+
color: #f44336;
|
| 77 |
+
text-decoration: none;
|
| 78 |
+
font-size: 14px;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
.delete-btn:hover {
|
| 82 |
+
text-decoration: underline;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.empty-list {
|
| 86 |
+
color: #999;
|
| 87 |
+
text-align: center;
|
| 88 |
+
font-style: italic;
|
| 89 |
+
}
|
project/templates/index.html
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Simple To-Do App</title>
|
| 7 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
| 8 |
+
</head>
|
| 9 |
+
<body>
|
| 10 |
+
<div class="container">
|
| 11 |
+
<h1>Simple To-Do List</h1>
|
| 12 |
+
|
| 13 |
+
<form action="/add" method="POST" class="task-form">
|
| 14 |
+
<input type="text" name="task" placeholder="Enter a new task..." required>
|
| 15 |
+
<button type="submit">Add Task</button>
|
| 16 |
+
</form>
|
| 17 |
+
|
| 18 |
+
<ul class="task-list">
|
| 19 |
+
{% if tasks %}
|
| 20 |
+
{% for task in tasks %}
|
| 21 |
+
<li>
|
| 22 |
+
<span class="task-text">{{ task }}</span>
|
| 23 |
+
<a href="{{ url_for('delete', task_id=loop.index0) }}" class="delete-btn">Delete</a>
|
| 24 |
+
</li>
|
| 25 |
+
{% endfor %}
|
| 26 |
+
{% else %}
|
| 27 |
+
<li class="empty-list">No tasks yet! Add one above.</li>
|
| 28 |
+
{% endif %}
|
| 29 |
+
</ul>
|
| 30 |
+
</div>
|
| 31 |
+
</body>
|
| 32 |
+
</html>
|