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
How to make so that if the user is not authorized, it from any page redirects to the login page. LOGIN_URL not working(
path('login/', auth_views.login, name='login')
LOGIN_URL = '/login/'
by | 18 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))
0 like 0 dislike
Use a view decorator login_required()

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,186 answers
35,573 users