0
我有一個檢查用戶配置文件的中間件。如果auth用戶沒有配置文件,則重定向到用戶配置文件。我的瀏覽器顯示錯誤The page isn’t redirecting properly
。django - 頁面沒有正確重定向
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/')
我使用django-allauth
。
我相信裏面'HttpResponseRedirect'你應該使用['reverse'(https://docs.djangoproject.com/en/dev/ref/urlresolvers/#django.urls.reverse)功能。這應該做到這一點。 –