Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Flask Basics Character Builder Starting the Builder

How did we set the cookie for colors? [solved?]


I can't grasp how did we set the cookie for the color in this video, we explicitly set the cookie in the last video with

response.set_cookie('character_name', json.dumps(data))

but in here it is not explained how we did it.

Your answer will be very appreciated!

Ok here's the result of my investigation, please correct me if I am wrong. We will not set a new cookie but just add a key-value pair to the existing cookie.

  1. the user chooses the color, and hits update. The form element will then send a POST request to the /save view
  2. the /save view will then redirect us back to the /builder view
  3. /save will call the get_saved_data() method and then will update the cookie (data)
  4. the new data will be stored in request.form which will now have an immutablemultidict with an extra key 'colors' names in the input element and it's value '#chosen color'
  5. we will have the color available on the builder.html because saves.get('color') will have the 'checked' attribute attached to it which tells the CSS doc which background color to display and which radio button to be selected