Q:

Is there a logout_required equivalent to login_required in Django?

Django provides the very useful @login_required views.py decorator, which you can also call as a function (login_required()) in urls.py. It redirects a user without authentication to settings.LOGIN_URL.
Is there a similar decorator for @logout_required, such that the view is only rendered if the user is not authenticated, otherwise redirected to settings.LOGOUT_URL or equivalent?

A:

To the best of my knowledge, there is no buitlin one, since that does not restrict much: a user can simply log out and visit the view, so it will usually only make the site less convenient.
If you really want that, you can implement one, in a similar way as how @login_required is implemented [GitHub]. For example with:
from django.conf import settings
from django.contrib.auth.decorators import user_passes_test

def logout_required(function=None, logout_url=settings.LOGOUT_URL):
    actual_decorator = user_passes_test(
        lambda u: not u.is_authenticated,
        login_url=logout_url
    )
    if function:
        return actual_decorator(function)
    return actual_decorator
You here will need to define a LOGOUT_URL yourself in your settings, since otherwise accessing the LOGOUT_URL will fail.

