Probably you want to create a custom admin login, in this article, we'll learn how to create a custom admin login by using the LoginView.

example

views.py


#loginView
from django.contrib.auth.views import LoginView    

class AdminLogin(LoginView):
    template_name = 'LoginView_form.html'

in View.py, we've created AdminLogin by subclassing LoginView, and then we've defined template_name which is the template that will contain our login form.

urls.py


#LoginView
path('login/', AdminLogin.as_view(), name="login")

n our URLs, we'have added path for AdminLogin

settings.py

in settings.py you should add login redirect URL, as the following code


LOGIN_REDIRECT_URL = 'home' # url redirecting after a successful authentication

LoginView_form.html

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<html>
    <head>
        <title>UpdateView</title>
        
    </head>

    <body>
<form method="POST">{% csrf_token %}
    
<!-- form variable -->    
 {{ form.as_p }} 

  <input type="submit" name="sumbit">
</form>
    </body>

</html>

go to /login in you browser you will see the login form if you login successful the browser will rediret to /home

English today is not an art to be mastered it's just a tool to use to get a result