问题
I have a middleware that check user profile. If auth user doesn't have a profile, then redirect to user profile. My browser displays the error The page isn’t redirecting properly
.
class Check(MiddlewareMixin):
def process_request(self, request):
if request.user.is_authenticated():
user = request.user
try:
profile = Profile.objects.get(user_id = user)
if profile:
pass
except ObjectDoesNotExist:
return HttpResponseRedirect('/accounts/profile/')
I'm use django-allauth
.
回答1:
It sounds like you might have an infinite redirect loop. Check the request path, and do not redirect if the user is trying to access /accounts/profile/
.
class Check(MiddlewareMixin):
def process_request(self, request):
if request.user.is_authenticated() and request.path != '/accounts/profile/':
...
来源:https://stackoverflow.com/questions/42674973/django-the-page-isn-t-redirecting-properly