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"
Furthermore, optional dark theme color variants can be specified. The dark theme colors default to the non-dark theme colors.
ADMIN_NOTICE_TEXT_COLOR_DARK = "#f2f2f2"
ADMIN_NOTICE_BACKGROUND_DARK = "#FA8072"
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
Release history Release notifications | RSS feed
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
File details
Details for the file django_admin_notice-3.2.0.tar.gz
.
File metadata
- Download URL: django_admin_notice-3.2.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.11.6-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8391cfecd32f27322b37328440ebb5c3788d18cdf27dac91397e52da47f23230 |
|
MD5 | 2f2665307108629edebb7b3231b994a8 |
|
BLAKE2b-256 | de911e85601cd7e0635bf1d627a1a9b135188d137736d6c38633d3f7de5fd3ab |
File details
Details for the file django_admin_notice-3.2.0-py3-none-any.whl
.
File metadata
- Download URL: django_admin_notice-3.2.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.11.6-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 552c49707fe8ee4d177000e5040beb1c172137a804efbc6ecbcbd49aa9d77f64 |
|
MD5 | c0517fae64f12c4ddda38282f6e73b7c |
|
BLAKE2b-256 | 7b1e1f3ef5b84e22dab1e155c5c93eddd0750e7e8e49fb7740f68fc2e0d10e05 |