1from django.contrib.auth import logout
2
3def logout_view(request):
4 logout(request)
5 # Redirect to a success page.
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
1from django.contrib.auth.mixins import LoginRequiredMixin
2
3LOGIN_URL = 'your_url'
1{% extends 'main/header.html' %}
2
3{% block content %}
4
5 <div class="container">
6 <form method="POST">
7 {% csrf_token %}
8 {{form.as_p}}
9 <button style="background-color:#F4EB16; color:blue" class="btn btn-outline-info" type="submit">Login</button>
10 </form>
11 Don't have an account? <a href="/register" target="blank"><strong>register here</strong></a>!
12 </div>
13{% endblock %}