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

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,972 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.