My final project is a task website that allows you to create tasks, complete them, and get alerted when you haven't done a task on time. Currently, I am working on alerting when the task is due. The date due saves to my database, but when I run my for loop on index.html that iterates through the user's tasks to see if they're due that day, the loop doesn't do anything. Please tell me if you have an idea of why this is happening.
Application.py:
@app.route("/", methods=["GET", "POST"])
def index():
if session.get("user_id") is None:
return redirect("/login")
if request.method == "POST":
db.execute("DELETE FROM tasks WHERE task = :task AND user_id = :user_id", task=request.form.get("complete"), user_id=session["user_id"])
rows=db.execute("SELECT * FROM tasks WHERE user_id = :user_id", user_id=session["user_id"])
return render_template("index.html", rows=rows)
else:
timestamp=datetime.now()
current_date=timestamp.date()
rows=db.execute("SELECT * FROM tasks WHERE user_id = :user_id", user_id=session["user_id"])
return render_template("index.html", rows=rows, current_date=current_date)
Index.html
{% extends "layout.html" %}
{% block title %}
Home
{% endblock %}
{% block main %}
<h1>MyTasks</h1>
<center>
{% for i in rows %}
{% if current_date == i["date_due"] %}
<div>Your task {{i["task"]}}, due today, has not been completed.</div>
{% endif %
{% endfor %}
<a href="/add" target="_blank" class="button">New Task</a>
<br><br><br>
{% for i in rows %}
<br>
<div type="text">-{{i["task"]}}</div>
{% endfor %}
<br><br>
<form method="POST" class ="ey">
<select name="complete">
<option>~Select~</option>
{% for i in rows %}
<option>{{i["task"]}}</option>
{% endfor %}
</select>
<button name="complete_button" class="button">Complete</button>
</form>
</center>
{% endblock %}