1from django.contrib.auth import logout
2
3def logout_view(request):
4 logout(request)
5 # Redirect to a success page.
6
1from django.contrib.auth import authenticate, login
2
3def my_view(request):
4 username = request.POST['username']
5 password = request.POST['password']
6 user = authenticate(request, username=username, password=password)
7 if user is not None:
8 login(request, user)
9 # Redirect to a success page.
10 ...
11 else:
12 # Return an 'invalid login' error message.
13 ...
14
1
2#loginView
3from django.contrib.auth.views import LoginView
4
5class AdminLogin(LoginView):
6 template_name = 'LoginView_form.html'
7
8
1path('accounts/login/', auth_views.LoginView.as_view(template_name='myapp/login.html')),
2