You could do something like `if hasattr(request, 'session', None):`