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! While you're at it, check out some resources Treehouse students have shared here.

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

Python Flask Basics Character Builder Starting the Builder

Lucas Navalesi
Lucas Navalesi
3,600 Points

Where does the key "name" come from?

Maybe I'm asking something very obvious but I can not understand ...

{{Save.get ('name', '')}}

1) "saves" is equal to "data". In turn, "save" is the json (and dict?) Conversion of the cookie we set in the func "save ()" ... right?

2) With json.dumps what we did was a str of a dict of an immutable dict that we delivered the form. To that result we established it as the cookie ...?

3) In the unlikely event that pts 1 and 2 are fine ... at what time we have the key "name" in our cookie? "Name" is by default?

Thank you !!!

2 Answers

Zach Swift
Zach Swift
17,984 Points

The 'name' key comes from the html form. If you look at line 9 in builder.html, the input element has a name property with a value of name. When the form is submitted, the data is sent to flask in a dictionary like object with the name property and whatever the user entered as the value. Now in app.py, in the save function on line 28, you're updating the character cookie dict with the keys and values of the form.