Reputation: 15814
One of the ways to delete a Django session variable is:
del request.session["sess_variable"]
This naturally gives a KeyError
exception in case sess_variable
wasn't in the request.session
dictionary.
To handle this exception, one can wrap the line in try
, except KeyError
. But is there a separate command one can use that doesn't throw an error if the key doesn't exist?
Upvotes: 0
Views: 784