A Guided Study Tasks Application
Learning Objectives
- You can combine list rendering, a form submission, and a redirect.
- You can connect a route to the supplied addition function.
- You can extend a working list page with a submission route.
Combine list rendering and form submissions in one Study Tasks application. You complete the routes and template using supplied addition and storage functions.
Use the completed local project from Chapter 7 as a reference. The exercise focuses on the list and addition form; search and detail pages are left out.
Suppose the file contains two tasks. A visitor submits title Prepare a summary with category writing. The supplied function stores a new record with trimmed text and a generated identifier. POST redirects, and the following GET displays three records and an empty form.
First, display the current records in a list. This first exercise is worth 20 points.
Display Study Tasks
0 / 20 points
Complete show_tasks in main.py and the list in templates/tasks.html.
Render the current records from read_records(DATA_FILE) under tasks. Show each title followed by its category in parentheses, in stored order. An empty collection has no task items. Leave the JSON file unchanged and use ordinary Jinja insertion so task text remains text.
Completing the list unlocks the addition exercise, also worth 20 points. Its starter includes a sample list implementation and an addition form. Connect the POST route to the supplied addition function, then redirect to the list.
Add a Study Task
0 / 20 points
Complete add_from_form in main.py.
Call the supplied add_task(DATA_FILE, title, category) once with the original submitted strings. Then return a 303 redirect to /tasks. The completed list and addition form are supplied.
The next chapter examines the supplied addition function’s storage operations.
Check Your Understanding
- The reader returns three task records, but the rendered list is empty. Which values would you follow from
show_tasksintotasks.htmlto locate the missing connection? - The POST route redirects successfully, but no new task is stored. Which application step could be missing even though the redirect works?
- After a successful addition, why should the next GET read the records again instead of reusing the list from the earlier page?