Python Flask Basics Character Builder Starting the Builder

Yahya Alshwaily
seal-mask
.a{fill-rule:evenodd;}techdegree
Yahya Alshwaily
Python Development Techdegree Student 5,640 Points

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

Hi,

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!

Yahya Alshwaily
seal-mask
.a{fill-rule:evenodd;}techdegree
Yahya Alshwaily
Python Development Techdegree Student 5,640 Points

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