Didina Deen Didina Deen - 1 year ago 133
Python Question

Redirect to login when session cookie expires in Django

I'm trying to redirect to the login page when the cookie expires but it's not working.

It's supposed to be as simple as adding these lines to settings.py:

LOGIN_URL = '/login/'

I'm using the decorator @login_required in my functions and I have tried @login_required(login_url='/login/') too.

Urls are correctly set and when manually going to /login it works, so it's not an error in the path.

When the session cookie expires and you try to access the app it gives you the error 'ViewDoesNotExist' (Could not import django.views.generic.simple.redirect_to. Parent module django.views.generic.simple does not exist.).

Answer Source

Something in your code is trying to import redirect_to, which was removed in Django 1.5. You need to find this code and update it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download