Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
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
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.
- the user chooses the color, and hits update. The form element will then send a POST request to the /save view
- the /save view will then redirect us back to the /builder view
- /save will call the get_saved_data() method and then will update the cookie (data)
- 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'
- 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