In-Class Activity 9: Form Editing and Deleting Topics:

Objective: Learn how to write a function and generate form data to edit existing entries. Write an additional function to delete a topic.

Description: Create a view function to allow users to edit entries on a form that have already been added. Also, write an additional view function to allow users to remove a specific topic.

  • Make a copy of your Activity8 folder and name the folder Activity9-FormEdit-TopicDelete. After the activity is completed, take three screenshots matching the solution images below and submit it to the first quiz question on Canvas.
  • Navigate to the directory that contains manage.py and open the folder in VS code.

Part 1: Editing Existing Entries

  1. Append the urls.py file (code_journals/urls.py) to add an additional URL pattern for the edit_entry page. This pattern should send requests to the view function edit_entry().
  2. Define a new view function named, edit_entry. The function should return a form for editing the entry when it receives a GET request. Alternatively, when a POST request is received, the revised entry text should save to the database.
  3. Create a new template called edit_entry.html to display the form. Ensure that the template extends base.html.
  4. Next, edit the topic template (topic.html) to include a link to the edit_entry page for each entry on the topic page.
  • The first screen capture below shows what the topic page should look like with the edit entry link added. Once the user clicks the link, the edit entry page should appear, as shown below in the second screen capture.

Web browser screenshot of the Code Journal topic page for Dictionaries. The page shows breadcrumb links reading Code Journal - Topics - Visuals, a heading reading Topic: Dictionaries, a section label reading Entries:, a link reading add new entry, and an entry card with the date Nov 06, 2026 06:31. The entry text reads In Python, a dictionary is a set of keys with data values. More precisely, a Python dictionary is a collection of key-value pairs. Below it appears bold text reading This entry has been edited! and a link reading edit entry. The scene is a simple local development page at 127.0.0.1:8000 with a light gray background and blue links, giving a clear and focused instructional tone.

Code Journal page centered on the Dictionaries topic with breadcrumb navigation at the top and a saved entry listed below the Entries heading. The visible interface emphasizes the topic content and the newly saved note, demonstrating where learners review what they entered. The environment is a minimal browser page with plain styling and strong text contrast, creating an organized and calm tone for reading study notes.


Part 2: Deleting a Topic

  1. Append the urls.py file (code_journals/urls.py) to add an additional URL pattern for deleting a topic. This pattern should send requests to the view function delete().
  2. Add a new view function named, delete. The function should get the request and the topic_id and then return a redirect to the topics URL pattern using the reverse function.
  3. Finally, edit the topics template (topics.html) to include a link, allowing a user to delete a topic of their choosing.
  • The below screen capture shows the updated topics page with links displayed next to each topic, allowing users to remove the topic of their choice. Note for the activity you don’t have to delete a topic, but the functionality should work.

Code Journal topics page showing a list of topic links with adjacent delete links so a user can remove a selected topic. The interface demonstrates the delete action in context and supports quick topic management from one screen. The wider environment is a straightforward browser page used in a local class project, with a clean background, simple text links, and an efficient practical tone.