S
S
Sergey Tryapkin2019-03-12 12:13:51
Django
Sergey Tryapkin, 2019-03-12 12:13:51

Block access to the site to unauthorized users?

Good afternoon.
How to implement this mechanism correctly?
Because asked to make a site "for their own", it is required to completely close access for users from outside.
I found it through middleware:

class AuthRequiredMiddleware(object):
    def process_request(self, request):
        if not request.user.is_authenticated():
            return HttpResponseRedirect(reverse('landing_page')) # or http response
        return None

+
MIDDLEWARE_CLASSES = (
    ...
    'path.to.your.AuthRequiredMiddleware',
)

How relevant is this option?
Maybe there are other ways?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Tikhonov, 2019-03-12
@Triapkin

How relevant is this option?
Maybe there are other ways?

At 100%. There is.
Yes, in general, everything is implemented correctly, except that all pages will lead to an endless redirect to 'landing_page''.

Y
Yura Khlyan, 2019-03-12
@MAGistr_MTM

Django-stronghold

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question