Django Registration Login: HTML Tutorial

Ann Jul 09, 2026

Streamlining user authentication is a crucial aspect of web development, and Django, a high-level Python web framework, provides robust tools for registration and login functionality. This article delves into creating HTML templates for Django's built-in registration and login views, ensuring a seamless user experience while maintaining the security of your web application.

Django Login And Registration With Source Code
Django Login And Registration With Source Code

Django's authentication system is designed to handle user registration and login out of the box. By using Django's built-in views and forms, you can create a secure and user-friendly authentication process with minimal effort. Let's explore how to create HTML templates for these views.

Add Google Login to Your Django App with Allauth
Add Google Login to Your Django App with Allauth

Setting Up Django Registration and Login

Before diving into creating HTML templates, ensure you have enabled Django's authentication system in your project's settings. Add 'django.contrib.auth' and 'django.contrib.contenttypes' to your INSTALLED_APPS, and set 'django.contrib.auth.middleware.AuthenticationMiddleware' in MIDDLEWARE.

login form html css
login form html css

Next, include the authentication URLs in your project's urlpatterns. Django provides 'django.contrib.auth.urls' which includes views for login, logout, password reset, and more. Here's how you can include them:

Including Django's Authentication URLs

Html, Css Login Tamplates
Html, Css Login Tamplates

In your project's urls.py, import 'django.contrib.auth.urls' and include it in your urlpatterns. This will map the authentication views to their respective URLs. Here's an example:

from django.urls import path, include

urlpatterns = [ path('accounts/', include('django.contrib.auth.urls')), # ... other URL patterns ]

Django HttpRequest
Django HttpRequest

Creating Custom Login and Registration Templates

While Django's default templates are functional, you might want to create custom templates to match your website's design. Django allows you to override these templates by creating your own in a 'templates' directory within your app. Here's how to create custom login and registration templates:

Create a new directory named 'registration' inside your app's 'templates' directory. Inside this 'registration' directory, create two new files named 'login.html' and 'registration/login.html'. These will be used for Django's login and registration views, respectively.

Django REST Framework Tutorial – Register Login Logout API
Django REST Framework Tutorial – Register Login Logout API

Designing Custom Login and Registration Templates

Now that you have created the necessary directories and files, let's design the HTML templates for Django's login and registration views.

the web page for django
the web page for django
Creating Blog User Logins With Authentication - Django Blog #9
Creating Blog User Logins With Authentication - Django Blog #9
Login page through HTML and CSS
Login page through HTML and CSS
Django Allauth: Installation & Setup
Django Allauth: Installation & Setup
the diagram shows how to use django
the diagram shows how to use django
Animated Login and Registration Form in HTML CSS & Javascript
Animated Login and Registration Form in HTML CSS & Javascript
an image of a computer screen showing the program's name and numbers on it
an image of a computer screen showing the program's name and numbers on it
the sign in screen for an app
the sign in screen for an app
Login and Registration Form in HTML & CSS
Login and Registration Form in HTML & CSS
How to Create a Login System in Python Using Django? | Python Projects | GeeksforGeeks
How to Create a Login System in Python Using Django? | Python Projects | GeeksforGeeks
Free 22+ HTML5 Signup & Registration Forms - HTML, CSS
Free 22+ HTML5 Signup & Registration Forms - HTML, CSS
Django Allauth: Email Verification (Console Method)
Django Allauth: Email Verification (Console Method)
How To Make A Website With Login And Register | HTML CSS & Javascript
How To Make A Website With Login And Register | HTML CSS & Javascript
C#,  JAVA,PHP, Programming ,Source Code: Java - Login And Register Form Design
C#, JAVA,PHP, Programming ,Source Code: Java - Login And Register Form Design
How to Implement Login, Logout, and Registration with Django’s User Model.
How to Implement Login, Logout, and Registration with Django’s User Model.
a login screen with mountains and trees in the background at night, under a full moon
a login screen with mountains and trees in the background at night, under a full moon
Django Views
Django Views
Django Insert Data Into Database with Source Code
Django Insert Data Into Database with Source Code
two business cards with an image of a programming program on the front and back side
two business cards with an image of a programming program on the front and back side
Free Bootstrap 4 Login Form
Free Bootstrap 4 Login Form

Creating a Custom Login Template

Open your app's 'templates/registration/login.html' file and start designing your custom login form. Here's a basic example using Bootstrap classes for styling:

<form method="post"> <% csrf_token %> <div class="form-group"> <label for="id_username">Username</label> <input type="text" name="username" class="form-control" id="id_username"> </div> <div class="form-group"> <label for="id_password">Password</label> <input type="password" name="password" class="form-control" id="id_password"> </div> <input type="submit" value="Login" class="btn btn-primary"> </form>

This template includes Django's {% csrf_token %} template tag to protect against Cross Site Request Forgeries. It also uses Bootstrap's form classes for styling.

Creating a Custom Registration Template

To create a custom registration template, open your app's 'templates/registration/login.html' file and design your registration form. Here's an example using Django's built-in registration form and Bootstrap classes:

<form method="post"> <% csrf_token %> <table> <tr> <td><label for="id_username">Username</label></td> <td><input type="text" name="username" class="form-control" id="id_username"></td> </tr> <tr> <td><label for="id_email">Email</label></td> <td><input type="email" name="email" class="form-control" id="id_email"></td> </tr> <tr> <td><label for="id_password1">Password</label></td> <td><input type="password" name="password1" class="form-control" id="id_password1"></td> </tr> <tr> <td><label for="id_password2">Password confirmation</label></td> <td><input type="password" name="password2" class="form-control" id="id_password2"></td> </tr> </table> <input type="submit" value="Register" class="btn btn-primary"> </form>

This template uses a table for layout and includes Django's built-in password confirmation field.

With these custom templates, your Django application will now use your custom designs for user registration and login. This allows you to maintain a consistent look and feel across your website while providing a secure and user-friendly authentication experience.