Implementing a logout functionality
We’ll follow the following steps:
- Configure a logout URL.
- Define the
logout
function. - Add a link to the base template.
We’ll undertake these steps in the upcoming sections.
Configuring a logout URL
In /accounts/urls.py
, add the path that is in bold:
from django.urls import path from . import views urlpatterns = [ path('signup', views.signup, name='accounts.signup'), path('login/', views.login, name='accounts.login'), path('logout/', views.logout, name='accounts.logout'), ]
Now, if a URL matches the /accounts/logout
path, it will execute the logout
function defined in the views
file.
Defining the logout function
In /accounts/views.py
, add the following lines that are in bold:
from django.shortcuts import render from django.contrib.auth import login as auth_login...