A cookie is a small piece of data that a browser stores and sends with requests. In a Flask practice-test application, it preserves a database-backed session ID so refreshed pages keep the same session. section 6.2.1 section 6.2.2
A practical session-cookie flow:
- Read the session_id cookie when the index route loads. section 6.2.2
- Create a database session when no cookie value exists. section 6.2.2
- Return the rendered page through a response and set the generated ID with response.set_cookie. section 6.2.2
- Delete the cookie and reload the page to end the test and begin a new session. section 6.2.4
Prompt, review, and correction
A developer asks an AI coding assistant how to store a Flask session ID in a cookie, applies the suggested diff, then fixes an error caused by accessing a session before it exists. The final workflow creates the session when needed, persists its ID, and keeps that ID across refreshes. AI accelerates the routine code, but human review catches context and lifecycle errors. section 6.2.1 section 6.2.2 section 6.2.4
<h1>Data</h1>
Inspect the response.set_cookie implementation and the JavaScript that removes session_id before reloading the page. section 6.2.2 section 6.2.4









