filmov
tv
Python Flask WT-Form Demo: Nobel-Prize API -- Adding sessions and cookies

Показать описание
In this video we use Python, Flask, WT-Forms and the "requests" library to generate a form that allows a user to select a Nobel Prize category (physics, chemistry, etc.) as well as a year ( 2000, 2001, ...). We add the idea of session and cookie to our previous version. We see how to set a session variable in Python and access a session variable (if it exists) both in Python and in Jinja. Then we see how to set a cookie in Python and to give it a life span and how to access a cookie (if it exists) in Jinja. We compare and contrast sessions and cookies. Session variables are updated sooner and live as long as the browser in question is open. A cookie's value may "lag" behind because it is associated only with the request and not the response. However, a cookie with a life span will be remembered even if the browser has closed (so long as it has not expired).