Answers for "django logout view"

1

django logout

from django.contrib.auth import logout

def logout_view(request):
    logout(request)
    # Redirect to a success page.
Posted by: Guest on February-02-2021
5

user login validation django

from django.contrib.auth import authenticate, login

def my_view(request):
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(request, username=username, password=password)
    if user is not None:
        login(request, user)
        # Redirect to a success page.
        ...
    else:
        # Return an 'invalid login' error message.
        ...
Posted by: Guest on June-12-2020
4

loginrequiredmixin

from django.contrib.auth.mixins import LoginRequiredMixin

LOGIN_URL = 'your_url'
Posted by: Guest on October-18-2020

Python Answers by Framework

Browse Popular Code Answers by Language