When using the new LoginRequiredMiddleware in django 5.1 which reverses the login_required decorator so it forces login required on all views except the views excluded via @login_not_required
So the login view for django unfold now enters an infinite loop of login redirect.
Solution
# in unfold.sites.UnfoldAdminSite
...
from django.contrib.auth.decorators import login_not_required
from django.utils.decorators import method_decorator
from django.views.decorators.cache import never_cache
...
class UnfoldAdminSite(AdminSite):
...
@method_decorator(never_cache)
@login_not_required
def login(
self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = None
) -> HttpResponse:
...
What version of Unfold are you using?
main
What version of Django are you using?
5.1
Describe your issue
When using the new
LoginRequiredMiddleware
in django 5.1 which reverses the login_required decorator so it forces login required on all views except the views excluded via@login_not_required
So the login view for django unfold now enters an infinite loop of login redirect.
Solution