I'm working on a Django project where I'm using the Jazzmin package to customize the Django admin interface. I've created a custom login page (custom_login.html) for the admin interface, and I want to hide the sidebar and navbar on this page. However, even after ensuring that the {% block nav-global %} and {% block nav-sidebar %} blocks are empty in my custom login template, and that the Jazzmin CSS and JavaScript files are not included on the login page, the sidebar and navbar are still showing up.
I've tried several approaches, including selectively including the Jazzmin files, overriding the base template to conditionally include the Jazzmin files, and removing custom CSS and JavaScript from my custom login template. However, none of these solutions have worked so far.
I've also inspected the HTML of the custom login page using my browser's developer tools and checked for JavaScript errors in the console, but I couldn't find any obvious issues.
Here are the relevant parts of my code: custom_login.html
{% extends "admin/base_site.html" %}
{% load i18n static %}
{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" href="{% static "admin/css/login.css" %}">
<style>
.login #id_tenant {
height: 2.5rem !important;
padding: 8px;
width: 100%;
}
</style>
{{ form.media }}
{% endblock %}
{% block bodyclass %}{{ block.super }} login{% endblock %}
{% block usertools %}{% endblock %}
{% block nav-global %}{% endblock %}
{% block nav-sidebar %}{% endblock %}
{% block content_title %}{% endblock %}
{% block nav-breadcrumbs %}{% endblock %}
{% block content %}
{% if form.errors and not form.non_field_errors %}
<p class="errornote">
{% blocktranslate count counter=form.errors.items|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktranslate %}
</p>
{% endif %}
{% if form.non_field_errors %}
{% for error in form.non_field_errors %}
<p class="errornote">
{{ error }}
</p>
{% endfor %}
{% endif %}
<div id="content-main">
{% if user.is_authenticated %}
<p class="errornote">
{% blocktranslate trimmed %}
You are authenticated as {{ username }}, but are not authorized to
access this page. Would you like to login to a different account?
{% endblocktranslate %}
</p>
{% endif %}
<form action="{{ app_path }}" method="post" id="login-form">{% csrf_token %}
<div class="form-row">
{{ form.username.errors }}
{{ form.username.label_tag }} {{ form.username }}
</div>
<div class="form-row">
{{ form.password.errors }}
{{ form.password.label_tag }} {{ form.password }}
<input type="hidden" name="next" value="{{ next }}">
</div>
<div class="form-row">
{{ form.tenant.errors }}
{{ form.tenant.label_tag }} {{ form.tenant }}
</div>
{% comment %} {% url 'admin_password_reset' as password_reset_url %}
{% if password_reset_url %}
<div class="password-reset-link">
<a href="{{ password_reset_url }}">{% translate 'Forgotten your password or username?' %}</a>
</div>
{% endif %} {% endcomment %}
<div class="submit-row">
<input type="submit" value="{% translate 'Log in' %}">
</div>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('#id_tenant').on('change', function() {
var selectedTenant = $(this).val();
// Make an AJAX request to your Django view
$.ajax({
url: '/update-tenant/', // URL to your Django view
type: 'POST',
data: {
'selected_tenant': selectedTenant,
'csrfmiddlewaretoken': '{{ csrf_token }}' // Include CSRF token for security
},
success: function(data) {
// Handle success response
},
error: function(xhr, status, error) {
// Handle error
}
});
});
});
</script>
{% endblock %}
settings.py INSTALLED_APPS = [ 'jazzmin', ]
JAZZMIN_SETTINGS = {
# title of the window
"custom_login_template": "custom_login/templates/registration/login.html",
# 'site_title': 'WTC Admin',
'site_title': 'YOUR ORGANIZATION NAME Admin',
# Title on the brand, and the login screen (19 chars max)
# 'site_header': 'WTC Admin',
'site_header': 'YOUR ORGANIZATION NAME Admin',
# square logo to use for your site, must be present in static files, used for favicon and brand on top left
# 'site_logo': 'images/favicon.png',
'site_logo': 'images/newlogo.png',
# Welcome text on the login screen
# 'welcome_sign': 'Welcome to WTC',
'welcome_sign': 'Welcome to YOUR ORGANIZATION NAME',
# Copyright on the footer
# 'copyright': 'wtcmumbai',
'copyright': 'organization_name-mumbai',
# The model admin to search from the search bar, search bar omitted if excluded
'search_model': 'auth.User',
# Field name on user model that contains avatar image
'user_avatar': None,
############
# Top Menu #
############
# Links to put along the top menu
# 'topmenu_links': [
# # Url that gets reversed (Permissions can be added)
# {'name': 'Home', 'url': 'admin:index',
# 'permissions': ['auth.view_user']},
# {"name": "Forum Admin",
# "url": "http://35.239.95.43:8010/forum/forum-admin/", "new_window": True},
# # external url that opens in a new window (Permissions can be added)
# # model admin to link to (Permissions checked against model)
# {'model': 'auth.User'},
# # App with dropdown menu to all its models pages (Permissions checked against models)
# ],
#############
# User Menu #
#############
# Additional links to include in the user menu on the top right ('app' url type is not allowed)
#############
# Side Menu #
#############
# Whether to display the side menu
'show_sidebar': True,
# Whether to aut expand the menu
'navigation_expanded': True,
# Hide these apps when generating side menu e.g (auth)
'hide_apps': [],
# Hide these models when generating side menu (e.g auth.user)
'hide_models': [],
# List of apps (and/or models) to base side menu ordering off of (does not need to contain all apps/models)
# Custom links to append to app groups, keyed on app name
# Custom icons for side menu apps/models See https://www.fontawesomecheatsheet.com/font-awesome-cheatsheet-5x/
# for a list of icon classes
'icons': {
'auth': 'fas fa-users-cog',
'auth.user': 'fas fa-user',
'auth.Group': 'fas fa-users',
},
# Icons that are used when one is not manually specified
'default_icon_parents': 'fas fa-arrow-circle-right fa-lg',
'default_icon_children': 'fas fa-angle-right',
#############
# UI Tweaks #
#############
# Relative paths to custom CSS/JS scripts (must be present in static files)
"custom_css": 'scss/admin.css',
"custom_js": None,
# Whether to show the UI customizer on the sidebar
"show_ui_builder": False,
###############
# Change view #
###############
# Render out the change view as a single form, or in tabs, current options are
# - single
# - horizontal_tabs (default)
# - vertical_tabs
# - collapsible
# - carousel
"changeform_format": "single",
# override change forms on a per modeladmin basis
"changeform_format_overrides": {"auth.user": "collapsible", "auth.group": "vertical_tabs", },
# Add a language dropdown into the admin
"language_chooser": False,
}
JAZZMIN_UI_TWEAKS = {
"navbar_small_text": True,
"footer_small_text": True,
"body_small_text": True,
"brand_small_text": True,
"brand_colour": "navbar-navy",
"accent": "accent-navy",
"navbar": "navbar-info navbar-dark",
"no_navbar_border": False,
"sidebar": "sidebar-dark-info",
"sidebar_nav_small_text": True,
"sidebar_disable_expand": False,
"sidebar_nav_child_indent": False,
"sidebar_nav_compact_style": True,
"sidebar_nav_legacy_style": False,
"sidebar_nav_flat_style": False
}
FILE_UPLOAD_MAX_MEMORY_SIZE = 10485760
IMPORT_EXPORT_USE_TRANSACTIONS = True
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
# 'DEFAULT_PERMISSION_CLASSES': [
# 'rest_framework.permissions.IsAuthenticated',
# ],
# 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
}
urls.py
admin.site.login = CustomLoginView.as_view()