I am using the following code :
if request.session.get("name",False):
Can anyone please tell me what the above code does? What I assume is, if there is “name” in session it returns True, otherwise, it returns False. I’m confused with my code so I posted this question here.
Thanks.
If
sessionhas a key in it with the value"name"it returns the value associated with that key (which might well beFalse), otherwise (if there is no key named “name”) it returnsFalse.The
sessionis a dictionary-like type so the best place to get documenation on thegetmethod is in the Python docs for the standard library. The short of the matter is thatgetis shorthand for the following: