Show a floating notice banner above the Django admon interface
Project description
Django Admin Notice
Show a floating notice banner above the Django admin interface. Particularly useful for indicating the current deployment environment.
Installation
Install django-admin-notice by running pip install django-admin-notice
Add admin_notice
to your INSTALLED_APPS
somewhere before django.contrib.admin
.
INSTALLED_APPS = [
"admin_notice", # <-- Add this somewhere before "django.contrib.admin"
"django.contrib.admin",
# ... other apps
]
Add admin_notice.context_processors.notice
to the templates context_processors
.
Having django.template.context_processors.request
is required as well.
TEMPLATES = [
{
"OPTIONS": {
"context_processors": [
"django.template.context_processors.request", # <-- have this
"admin_notice.context_processors.notice", # <-- Add this
# ... other context processors
]
},
},
]
Settings
Set the ADMIN_NOTICE_TEXT
to the text you want to show above the admin interface.
No message is shown if this setting is missing or empty.
ADMIN_NOTICE_TEXT = "Production environment"
Optionally specify a custom text color and background for your notice.
The default text color is white
and the default background red
.
ADMIN_NOTICE_TEXT_COLOR = "white"
ADMIN_NOTICE_BACKGROUND = "red"
Tips
It's a common use case to indicate the projects deployment environment.
The following configuration shows how to obtain the django-admin-notice
configuration from environment variables and how to configure a fallback.
from os import environ
ADMIN_NOTICE_TEXT = environ.get("ADMIN_NOTICE_TEXT", "Local environment")
ADMIN_NOTICE_TEXT_COLOR = environ.get("ADMIN_NOTICE_TEXT_COLOR", "white")
ADMIN_NOTICE_BACKGROUND = environ.get("ADMIN_NOTICE_BACKGROUND", "green")
Example project
Take a look at our Django example project under tests/project
. You can run it by executing these commands:
poetry install
poetry run python tests/project/manage.py migrate
poetry run python tests/project/manage.py createsuperuser
poetry run python tests/project/manage.py runserver
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_admin_notice-2.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb0fb062456b13826b9a703e8845c1f903c41ed657b362c06a2d3e43605d851d |
|
MD5 | b6f1cdeb8a3c35cd9a9d7461b0a2b28a |
|
BLAKE2b-256 | 80969885a5e1c307f6b0e92dd77d16e7c521c2ffedf7aebac1340eeaaf954ca6 |
Hashes for django_admin_notice-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5974e441fa453c52d912047586484b4c278bca386e3d7c0ad8eebe54ff0f47e |
|
MD5 | d9b1b05f70040902edd515cce5f3dbf9 |
|
BLAKE2b-256 | 40d7fe98682a91dae2582f7172bfd0a2293b2f2d3cf99f56e9f05092126067dc |