Tsallaka zuwa abun ciki
Justice Tech School

Sessions and Cookies

request.session is a dictionary stored on the server and linked to a cookie. Use it for carts or preferences.

Example
def add_to_cart(request, pid):
    cart = request.session.get("cart", [])
    cart.append(pid)
    request.session["cart"] = cart
    return redirect("cart")

Exercise

Read a session value.

request..get("cart")

Quiz Test

Where is session data kept by default?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.