Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Django IntroductionChapter 5. User Management

Django Allauth (9) – Customize Sign-in and Sign-up Pages

Django Allauth (9) – Customize Sign-in and Sign-up Pages

Customizing Sign-in and Sign-up Pages in Django Allauth

The last part of the social login UI styling adjustment is for the Sign In (login) and Sign Up page. Currently, the social login UI design is just simple text, and social login is only available on the Sign In (login) page. In this section, we'll restructure the pages and add logos.

Add logos

As the links to the social login (e.g., GitHub and Google) are coming from the allauth source code, you may have difficulty replacing text links with image links. Here are the steps to add images to the social login links.

Prepare icons

We use these Google and GitHub icons for the links. To make them accessible by Django, save these image files under the images directory.

Google and GitHub icons
Google and GitHub png files

Define HTML elements to add icons

First, you need to identify the elements where you want to add the icons. This part may be the most challenging part.

To see where the GitHub's and Google's texts come from, check the account/login.html file. You can see that this HTML document includes another HTML document – socialaccount/snippets/provider_list.html.

templates/account/login.html
{% if socialaccount_providers %}
<p>{% blocktrans with site.name as site_name %}Please sign in with one
of your existing third party accounts. Or, <a href="{{ signup_url }}">sign up</a>
for a {{ site_name }} account and sign in below:{% endblocktrans %}</p>

<div class="socialaccount_ballot">

  <ul class="socialaccount_providers">
  {% include "socialaccount/snippets/provider_list.html" with process="login" %}
  </ul>

  <div class="login-or">{% trans 'or' %}</div>

</div>

{% include "socialaccount/snippets/login_extra.html" %}

{% else %}
<p>{% blocktrans %}If you have not created an account yet, then please
<a href="{{ signup_url }}">sign up</a> first.{% endblocktrans %}</p>
{% endif %}

Check the socialaccount/snippets/provider_list.html file to identify the location where the text data is coming from.

templates/socialaccount/snippets/provider_list.html
{% load socialaccount %}
{% get_providers as socialaccount_providers %}

{% for provider in socialaccount_providers %}
{% if provider.id == "openid" %}
{% for brand in provider.get_brands %}
<li>
  <a title="{{brand.name}}" class="socialaccount_provider {{provider.id}} {{brand.id}}" href="{% provider_login_url provider.id openid=brand.openid_url process=process %}">{{brand.name}}</a>
</li>
{% endfor %}
{% endif %}
<li>
  <a title="{{provider.name}}" class="socialaccount_provider {{provider.id}}" href="{% provider_login_url provider.id process=process scope=scope auth_params=auth_params %}">{{provider.name}}</a>
</li>
{% endfor %}

The text data comes from {{brand.name}} or {{provider.name}}. We found the location of the HTML code; however, we cannot add links to the images as {{brand.name}} and {{provider.name}} are variables.

To find more information, go to the browser and select "inspect" with a right-click.

Now, you can see the actual code implemented in a browser. The GitHub and Google elements have their own classes – github and google. We can utilize these class names to identify the location of the elements where we want to add images.

Django Allauth Social Login Sign In page HTML code

Add images to the elements

We can utilize the custom.css file to add images. In this example, we'll use the background-image property to show the icons. The path is the relative path from the CSS file to the image file. As this file is not a Django template, you don't need to use the {% url %} tag. Add several properties to adequately adjust the size of the icons.

static/css/custom.css
.github {
  display: inline-block;
  content: '';
  width: 50px;
  height: 50px;
  background-image: url("../images/github.png");
  background-size: contain;
}
.google {
  display: inline-block;
  content: '';
  width: 50px;
  height: 50px;
  background-image: url("../images/google.png");
  background-size: contain;
}

At this point, the icons are overlapping with the text. Also, there are list markers, and the icons are vertically listed.

Django Allauth Social Login Sign In page with Google and GitHub icons (before position adjusted)

To fix the page, edit socialaccount/snippets/provider_list.html by doing the following:

  • Add d-flex to arrange the icons horizontally
  • Delete the markers using the list-style-type property
  • Delete {{provider.name}}
templates/socialaccount/snippets/provider_list.html
{% load socialaccount %}
{% get_providers as socialaccount_providers %}
<div class="d-flex justify-content-center gap-3">
  {% for provider in socialaccount_providers %}
  {% if provider.id == "openid" %}
  {% for brand in provider.get_brands %}
  <li>
    <a title="{{brand.name}}"
class="socialaccount_provider {{provider.id}} {{brand.id}}"
href="{% provider_login_url provider.id openid=brand.openid_url process=process %}"
>{{brand.name}}</a>
  </li>
  {% endfor %}
  {% endif %}
  <li style="list-style-type: none;">
    <a title="{{provider.name}}" class="socialaccount_provider {{provider.id}}"
href="{% provider_login_url provider.id process=process scope=scope auth_params=auth_params %}">###delete###</a>
  </li>
  {% endfor %}
</div>

Now you can see a better design.

Django Allauth Social Login SignIn page with Google and GitHub icons (after position adjusted)

Adjust the layout of the Sign In and Sign Up pages

Typically, social login comes after the standard login approach. Also, social login should be available on the Sign Up page as well. In this part, we'll skip the detailed explanations as several minor adjustments are needed. Here are the high-level guidance and results.

Sign In page

Make the following adjustments:

  • Move up the standard login code before the social login code
  • Move the Forgot Password link to the right
  • Move the sign up link after the Sign In button
  • Add a horizontal line after the sign up link
  • Simplify the message for the social login
  • Adjust font sizes

Now you can see a much cleaner Sign In page.

Django Allauth Sign In Page with Social Login (Layout adjusted)

Sign Up page

Make the following adjustments:

  • Bring a social login code from the Sign In page
  • Add the {% load account socialaccount %} tag to make the social login code function
  • Adjust font sizes

Now you can see a much cleaner Sign Up page.

Django Allauth Sign Up Page with Social Login (Layout adjusted)

You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Setting Up a Production Database for Django

Production Database Setup

Creating Templates for Create and Update Pages

Template for Create and Update Page

Setting Up a Production Database for Django

Production Database Setup

Creating Templates for Create and Update Pages

Template for Create and Update Page

Tags:

CSS

Bootstrap

Django Templates

User Authentication

User Management

Social Login

django-allauth

Django Introduction
Course Content

Chapter 1. Django Key Concepts

Web Framework and Django

Websites vs. Django Web Apps

How Django Handles HTTP Request and HTTP Response

Django's MVT Framework

Django Templates vs. Django APIs

Chapter 2. Django Quick Start Guide

Install Python

Install Visual Studio Code

Create Project Directory

Set Up Virtual Environment

Install Django

Start Django Project

Run Server

Database Migration

URL dispatcher – urls.py

Create Superuser and Log In to Django Admin

Start App

Create HTML Templates

Create Views

Add URL Patterns

Project vs. App

Chapter 3. Django Models and Databases

Create a Database in Django

Relational Database

Create Django Models

Makemigrations and Migrate

Add Models in Django Admin – admin.py

Change Display Name of Record Objects

Django Models – Data Field Type

Django Models – Field Options

Django Models – Help Text Option

Django Models – Choices Option

Django Models – DateField with datetime Module

Django Models – Relationship Fields

Django Models – ID

Django Models – ForeignKey (OneToMany Relationship)

Django Models – OneToOneField

Django Models – ManyToManyField

Chapter 4. Create CRUD Web Application

CRUD Web Application

Basic CRUD Structure in Django

Django Generic Views

How To Write Class-Based Views with Generic Views

Generic View Basic Attributes

URL Dispatcher for CRUD Views

Django Templates for CRUD Views

Django Template Language (DTL)

Template for List Page

get_FOO_display method

Template for Detail Page

Template with Model Relations

Template for Create and Update Page

Template for Delete Page

Add Links – {% url %} tag

Extend Templates – {% extends %} tag

Check Developing App UI on Mobile Device

Django Templates with Bootstrap

Crispy Forms

Customize Views (1) – Change List Order

Customizing Views (2) – Filter Lists

Context

Customize Views (3) – Add Extra Context

Modularize Templates – {% include %} tag

Static Files in Development Environment – {% static %} tag

STATIC_URL and STATICFILES_DIRS

Create Index HTML

Chapter 5. User Management

User Authentication

Overview of User Management Functions

User Management Function Development with Django

Approaches to Building User Management Functions in Django

Django Allauth (1) – Introduction

Django Allauth (2) – Installation and Initial Settings

Django Allauth (3) – Email Verification via Console

Django Allauth (4) – Email Verification via Gmail

Django Allauth (5) – Social Login with GitHub

Django Allauth (6) – Social Login with Google

Django Allauth (7) – Allauth Template File Setup

Django Allauth (8) – Add Basic Styling with Bootstrap and Crispy Forms

Django Allauth (9) – Customize Sign-in and Sign-up Pages

User Models

Login Required – LoginRequiredMixin

User Login Status Icon on Navigation Bar

Chapter 6. Deploy Django App

Overview of Django App Deployment (1)

Overview of Django App Deployment (2)

Key Steps of Django App Deployment

Hosting Service Initial Settings (1) – AWS Lightsail setup

Hosting Service Initial Settings (2) – SSH Remote Connection

Manage Local Computer and Remote Server Simultaneously

Tips for Managing Local Development and Remote Production Environment

Hosting Service Initial Settings (3) – Clone Project Directory with GitHub

Production Database Setup

Django Production Settings (1) – Settings.py for Development and Production

Django Production Settings (2) – Production Settings

Django Production Settings (3) – django-environ and .env file

Static File Settings

Django and Dependency Installation on Production Server

Web Server and Application Server in Django

Application Server Setup – Gunicorn

Web Server Setup – Nginx

Domain Setup

SSL Setup – Certbot

Email Setting – SendGrid

Social Login for Production

Manage Local Development and Remote Production Environment

Chapter 1. Django Key Concepts

Web Framework and Django

Websites vs. Django Web Apps

How Django Handles HTTP Request and HTTP Response

Django's MVT Framework

Django Templates vs. Django APIs

Chapter 2. Django Quick Start Guide

Install Python

Install Visual Studio Code

Create Project Directory

Set Up Virtual Environment

Install Django

Start Django Project

Run Server

Database Migration

URL dispatcher – urls.py

Create Superuser and Log In to Django Admin

Start App

Create HTML Templates

Create Views

Add URL Patterns

Project vs. App

Chapter 3. Django Models and Databases

Create a Database in Django

Relational Database

Create Django Models

Makemigrations and Migrate

Add Models in Django Admin – admin.py

Change Display Name of Record Objects

Django Models – Data Field Type

Django Models – Field Options

Django Models – Help Text Option

Django Models – Choices Option

Django Models – DateField with datetime Module

Django Models – Relationship Fields

Django Models – ID

Django Models – ForeignKey (OneToMany Relationship)

Django Models – OneToOneField

Django Models – ManyToManyField

Chapter 4. Create CRUD Web Application

CRUD Web Application

Basic CRUD Structure in Django

Django Generic Views

How To Write Class-Based Views with Generic Views

Generic View Basic Attributes

URL Dispatcher for CRUD Views

Django Templates for CRUD Views

Django Template Language (DTL)

Template for List Page

get_FOO_display method

Template for Detail Page

Template with Model Relations

Template for Create and Update Page

Template for Delete Page

Add Links – {% url %} tag

Extend Templates – {% extends %} tag

Check Developing App UI on Mobile Device

Django Templates with Bootstrap

Crispy Forms

Customize Views (1) – Change List Order

Customizing Views (2) – Filter Lists

Context

Customize Views (3) – Add Extra Context

Modularize Templates – {% include %} tag

Static Files in Development Environment – {% static %} tag

STATIC_URL and STATICFILES_DIRS

Create Index HTML

Chapter 5. User Management

User Authentication

Overview of User Management Functions

User Management Function Development with Django

Approaches to Building User Management Functions in Django

Django Allauth (1) – Introduction

Django Allauth (2) – Installation and Initial Settings

Django Allauth (3) – Email Verification via Console

Django Allauth (4) – Email Verification via Gmail

Django Allauth (5) – Social Login with GitHub

Django Allauth (6) – Social Login with Google

Django Allauth (7) – Allauth Template File Setup

Django Allauth (8) – Add Basic Styling with Bootstrap and Crispy Forms

Django Allauth (9) – Customize Sign-in and Sign-up Pages

User Models

Login Required – LoginRequiredMixin

User Login Status Icon on Navigation Bar

Chapter 6. Deploy Django App

Overview of Django App Deployment (1)

Overview of Django App Deployment (2)

Key Steps of Django App Deployment

Hosting Service Initial Settings (1) – AWS Lightsail setup

Hosting Service Initial Settings (2) – SSH Remote Connection

Manage Local Computer and Remote Server Simultaneously

Tips for Managing Local Development and Remote Production Environment

Hosting Service Initial Settings (3) – Clone Project Directory with GitHub

Production Database Setup

Django Production Settings (1) – Settings.py for Development and Production

Django Production Settings (2) – Production Settings

Django Production Settings (3) – django-environ and .env file

Static File Settings

Django and Dependency Installation on Production Server

Web Server and Application Server in Django

Application Server Setup – Gunicorn

Web Server Setup – Nginx

Domain Setup

SSL Setup – Certbot

Email Setting – SendGrid

Social Login for Production

Manage Local Development and Remote Production Environment