Tuesday, December 3, 2019

What is login_required in Django



from django.contrib.auth.decorators import login_required

@login_required
def my_view(request):

If the user isn’t logged in, redirect to settings.LOGIN_URL, passing the current absolute path in the query string. Example: /accounts/login/?next=/polls/3/.

Another format is

@login_required(login_url='/accounts/login/')
def my_view(request):


References:
https://kite.com/python/docs/django.contrib.auth.decorators.login_required

No comments:

Post a Comment