Django request.session.get ("name", False) - What does this code mean?

I am using the following code:

if request.session.get("name",False):

Can someone please tell me what this code is doing? I suggest that if there is a "name" in the session, it returns True, otherwise it returns False. I got confused with my code, so I posted this question here.

Thank.

+5
source share
1 answer

If it sessionhas a key with a value "name"in it, it returns the value associated with this key (which may be False), otherwise (if there is no key with the name "name"), it returns False.

session - - , get Python . , get :

if "name" in request.session:
    result = request.session["name"]
else:
    result = False

if result:
    # Do something
+13

All Articles