How to automatically go to the login page?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
24 views
How to make so that if the user is not authorized, it from any page redirects to the login page. LOGIN_URL not working(
urls.py
path('login/', auth_views.login, name='login')

setting.py
LOGIN_URL = '/login/'
by | 24 views

2 Answers

0 like 0 dislike
LOGIN_URL works, just need to finish the documentation until the end

from django.conf import settings from django.shortcuts import redirect def my_view(request): if not request.user.is_authenticated(): return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
by
0 like 0 dislike
Use a view decorator login_required()
\rhttps://djbook.ru/rel1.8/topics/auth/default.html#...
by

Related questions

0 like 0 dislike
5 answers
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
110,608 questions
257,187 answers
0 comments
40,796 users