Reputation: 630
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
.
Upvotes: 1
Views: 3090
Reputation: 1086
Check your secret key in setting.py I solved this problem with to remove get_random_secret_key().
Before
SECRET_KEY = env.str("SECRET_KEY", get_random_secret_key())
After SECRET_KEY = env.str("SECRET_KEY")
Now Im using unique SECRET_KEY and it works fine in prod service.
Upvotes: 0
Reputation: 1343
Make sure you are using The Right view, in my case i was using:
view
class Blog_View(View):
model = Blog
template_name = 'blog.html'
instead of
Listview
class Blog_View(ListView):
model = Blog
template_name = 'blog.html'
Upvotes: 0
Reputation: 309049
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/':
...
Upvotes: 5