Python Flask Basics Character Builder Cookies

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: http://flask.pocoo.org/docs/0.12/api/#flask.render_template

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!

1 Answer

Afdol Rizki
Afdol Rizki
23,156 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.

Thanks Afdol.