Answer the question
In order to leave comments, you need to log in
How to automatically go to the login page?
How to make it so that if the user is not authorized, then he is redirected from any page to the login page. LOGIN_URL not working(
urls.py
setting.pypath('login/', auth_views.login, name='login')
LOGIN_URL = '/login/'
Answer the question
In order to leave comments, you need to log in
LOGIN_URL works, you just need to read the documentation to 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))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question