Django Allauth (8) – Add Basic Styling with Bootstrap and Crispy Forms
This lesson will explain how to add basic styling to the allauth pages quickly.
1. Add key modules in account/base.html
The template files for allauth extend the base.html file under the account directory. Thus, adding styles in this file can speed up the entire UI design formatting.
Add the three tags below in the base.html file under the account directory. You can quickly include css_link.html, navbar.html, and footer.html.
{% include "base/css_link.html" %}
{% include "base/navbar.html" %}
{% include "base/footer.html" %}
{% load i18n %}
<!DOCTYPE html>
<html>
:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% include "base/css_link.html" %}
<title>{% block head_title %}{% endblock %}</title>
:
<body>
{% include "base/navbar.html" %}
{% block body %}
:
{% endblock %}
{% include "base/footer.html" %}
</body>
</html>
2. Customize the navigation bar
The following part of the code in the account/base.html file is designed for the navigation bar. We'll utilize these codes in our navigation bar.
:
<div>
<strong>{% trans "Menu:" %}</strong>
<ul>
{% if user.is_authenticated %}
<li><a href="{% url 'account_email' %}">{% trans "Change E-mail" %}</a></li>
<li><a href="{% url 'account_logout' %}">{% trans "Sign Out" %}</a></li>
{% else %}
<li><a href="{% url 'account_login' %}">{% trans "Sign In" %}</a></li>
<li><a href="{% url 'account_signup' %}">{% trans "Sign Up" %}</a></li>
{% endif %}
</ul>
</div>
:
Cut the code above and paste it into navbar.html. And replace the existing tags for authentications.
Delete unnecessary parts (e.g., menu), and add classes "nav-item
" and "nav-link
" to the new tags.
Also, delete {% trans %}
tags.
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="{% url 'course_list'%}">List</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'course_create'%}">Create</a>
</li>
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{% url 'account_email' %}">Chang
Subscribe now for
uninterrupted access.