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 via the Python Package Index (PyPI):
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
Run python manage.py runserver after following the Installation section
to see a fully working example project.
Contributing
Setup
- Clone the repository and enter the cloned folder
- (optional) Create and activate a dedicated Python virtual environment
- Run
pip install -e ".[dev]"to install the projects requirements - (optional) Run
pre-commit installto install the pre-commit hook
Pre-commit hook
Our pre-commit hook formats and lints the code.
Formatting and linting
- Run
black admin_notice teststo format the code - Run
flake8 admin_notice teststo lint the code
Testing
- Run
py.test --cov admin_notice teststo run the tests in the current Python env - Run
toxto run the tests in all supported Python and Django environments
Makefile
All commands listed above have shortcut make recipes.
Take a look at the Makefile to learn more.
Release files for django-admin-notice 1.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-admin-notice-1.1.4.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_admin_notice-1.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.4 kB
Release files / django-admin-notice-1.1.4.tar.gz
| Download URL | django-admin-notice-1.1.4.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5be29e74a89ef0a0da2bf6f4810c18b34b7baa3c5e1460651b32320d74e16c9c
|
|
BLAKE2b-256 checksum How to use checksums |
74800b4de438a249e36ce4f4b75224b528c4e6a9429f9afb37d0a5e70480754c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10
|
Release files / django_admin_notice-1.1.4-py3-none-any.whl
| Download URL | django_admin_notice-1.1.4-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fec06baeee4095f3e66fdbdb030e7a6bbc31f3e2f1775d068c6de0dd71ec5b50
|
|
BLAKE2b-256 checksum How to use checksums |
dd571ebb1db6e2568cb3212d0d05681531e16c314dfe7e9a428c0bcaea54a993
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10
|