Build your own
login_required decorator and have it mark the function as decorated–probably the best place to mark it would be in the
from django.contrib.auth.decorators import login_required as django_l_r
# Here you're defining your own decorator called `login_required`
# it uses Django's built in `login_required` decorator
decorated_func = django_l_r(func)
decorated_func.func_dict['login_is_required'] = True
@login_required # Your decorator
Now you can check to see if a view was decorated like this…
# Assume `a_view` is view function
If you’re confused about Python decorators see this SO question/answer: How to make a chain of function decorators?
It seems that your situation is as follows:
1. You have pages that are secured and behind a login-required decorator
2. You have pages that are non-secure and can be visited in both a logged-in state and anonymous state.
If I understand your requirements, you want a user to be redirected to Main Page (Assuming this to be the Welcome Page that can be visited in both a logged-in and Anonymous state) when a user logs out.
Why wouldn’t you just limit the user’s ability to logout from only secure pages, and then set your redirect_url on logout to the welcome screen?
- Python gettext error: Can't convert '__proxy__' object to str implicitly
- What does it mean for an object to be unscriptable?
- Installed Virtualenv and activating virtualenv doesn't work