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.
Could anyone explain more about the "saves.get" used in the html templates?
Online documentations/references when we passed
saves from app.py can be found here:
return render_template('builder.html', saves=get_saved_data(), options=DEFAULTS)
But when used inside html templates, I can't find references or is there a way to know from python interpreter too?
Thanks in advanced!
Afdol Rizki23,158 Points
The saves variable is a dictionary that come from get_saved_data() method which convert the json object from cookie to a dictionary.
So, saves is a dictionary and a dictionary have a method called get, in this case saves.get() that returns a value of a specified key, the second parameter is the default value if the key is not found, saves.get('name', '').
The 'name' key come from the post request to '/save' route in request.form, because one of the input field in the form named 'name'. Hope its help you.