Answer the question
In order to leave comments, you need to log in
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',
)
Answer the question
In order to leave comments, you need to log in
How relevant is this option?
Maybe there are other ways?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question