Implementing the logout functionality
Create the logout path in /accounts/urls.py
with the following in bold:
… urlpatterns = [ path('signupaccount/', views.signupaccount, name='signupaccount'), path('logout/', views.logoutaccount, name='logoutaccount'), ]
In /accounts/views.py
, implement the logoutaccount
function with the following in bold:
… from django.contrib.auth.models import User from django.contrib.auth import login, logout from django.shortcuts import redirect from django.db import IntegrityError … def logoutaccount(request): logout(request) return redirect('home')
We simply call logout
and redirect
to go back to the home page.
We then need to have <a href>...