diff --git a/swh/web/common/utils.py b/swh/web/common/utils.py --- a/swh/web/common/utils.py +++ b/swh/web/common/utils.py @@ -247,7 +247,11 @@ in all swh-web templates. """ config = get_config() - if request.user.is_authenticated and not hasattr(request.user, "backend"): + if ( + hasattr(request, "user") + and request.user.is_authenticated + and not hasattr(request.user, "backend") + ): # To avoid django.template.base.VariableDoesNotExist errors # when rendering templates when standard Django user is logged in. request.user.backend = "django.contrib.auth.backends.ModelBackend"