Launch a local server using flask Output the ToDo task web application.
After that, when I arranged the template and executed flask run, the following error occurred.
app.py
UnboundLocalError: local variable 'count' referenced before assignment
Below is an excerpt of the part that caused the error
app.py
count = 0
@app.route("/updatedone/<int:item_id>")
def update_todoitemdone(item_id):
todolist.update(item_id)
count = count + 1
return render_template("showtodo.html", todolist=todolist.get_all(), result=count)
The variable count declared outside the function If you want to use it in a function, you have to declare it globally.
Below, after correction.
app.py(Revised)
count = 0
@app.route("/updatedone/<int:item_id>")
def update_todoitemdone(item_id):
todolist.update(item_id)
global count
count = count + 1
return render_template("showtodo.html", todolist=todolist.get_all(), result=count)
Every time you press done, the number will be added! (('ω') ノ
↓ Reference article ↓ ToDo list app created with VS Code and Flask
Recommended Posts