When you think about your question, it was easier for me to create a simple active_required decorator. It is very simple because we can use the user_passes_test function in django.contrib.auth.decorators .
Then the question arises: "How to combine login_required and active_required into one decorator?". We need to define a function that:
- takes a view function as an argument
- applies both decorators to it to create a new view function
- returns a new view function
Putting it all together, you have the following:
from django.contrib.auth.decorators import user_passes_test, login_required active_required = user_passes_test(lambda u: u.is_active, login_url=REACTIVATE_URL) def active_and_login_required(view_func): decorated_view_func = login_required(active_required(view_func)) return decorated_view_func
source share