Part -9

Authenticate Users In Django

from django.contrib.auth import views as auth_views
...
path('login/',auth_views.LoginView.as_view(template_name='users/login.html'),name='login'),
path('logout/',auth_views.LogoutView.as_view(),name='logout'),
{%extends ‘blogapp/base.html’%}
...
<form method='POST'>
{%csrf_token%}
{{form|crispy}}
<button type='submit'>Submit</button>
Need An Account? <a href='{%url 'register'%}'>Sign Up</a></form>
...
LOGIN_REDIRECT_URL='blog-home'
path('logout/',auth_views.LogoutView.as_view(template_name="users/logout.html"),name='logout'),{% extends "blogapp/base.html" %}
{% block body %}
<h2>You have been logged out</h2>
<a href="{% url 'login' %}">Log In Again</a>
{% endblock body %}

Posting Django Tutorials with Beginner to Advanced Projects

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store