[Answer]-Limit some users to only one page in Django

1πŸ‘

βœ…

If you don’t want to use the decorator approach, your best bet is to write a middleware that checks if request.user is activated or not, then redirect (to a page where they can reactivate their account preferably) when necessary.

Roughly you’d want something like this:

from django.shortcuts import redirect


class DeactivatedRedirectMiddleware(object):

    def process_request(self, request):
        if request.user and not request.user.is_anonymous():
            if request.user.deactivated and request.get_full_path() != '/some/url/':
                # redirect here
                return redirect('/some/url/')
        # ...
πŸ‘€K Z

0πŸ‘

You can use decorator function to check if user is activated and redirect him.
How to write a custom decorator in django?

πŸ‘€szaman

0πŸ‘

Use a view decorator.

Good article about it: http://passingcuriosity.com/2009/writing-view-decorators-for-django/

πŸ‘€Ponytech

Leave a comment