Reputation: 1054
I've saved an instance of User called "user_current" into a session variable. Please note, the class has some parameters, such as t_id_user, t_email, etc.
In Flask/Jinja2, how do I reference those parameters for the object embedded in the session variable?
Here's the code below that I used to create the class and instance, and store the instance of that object in a session variable.
Thanks!
class User:
def __init__(self, t_id_user, t_email, t_password, t_security_level, t_name_first, t_name_last, t_enabled, d_visit_first, d_visit_last):
self.t_id_user = t_id_user
self.t_email = t_email
self.t_password = t_password
self.t_security_level = t_security_level
self.t_name_first = t_name_first
self.t_name_last = t_name_last
self.t_enabled = t_enabled
self.d_visit_first = d_visit_first
self.d_visit_last = d_visit_last
def usersFillTest():
t_id_user = "1"
t_email = "[email protected]"
t_password = "passwordy"
t_security_level = "5"
t_name_first = "Testicular"
t_name_last = "McTesty"
t_enabled = "True"
d_visit_first = "2020/09/30"
d_visit_last = "2020/09/30"
user_current = User(t_id_user, t_email, t_password, t_security_level, t_name_first, t_name_last, t_enabled, d_visit_first, d_visit_last)
session["user_current"] = user_current
Would it be something like
{{ session["user_current"]["t_id_user"] }}
?
Upvotes: 0
Views: 162
Reputation: 2698
session["user_current"]
contains the object as you create it. Therefore you can access its members like this:
{{ session["user_current"].t_id_user }}
Upvotes: 2