Skip to main content

Show a floating notice banner above the Django admin interface

Project description

Django Admin Notice

PyPI License Tests

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

  1. Clone the repository and enter the cloned folder
  2. (optional) Create and activate a dedicated Python virtual environment
  3. Run pip install -e ".[dev]" to install the projects requirements
  4. (optional) Run pre-commit install to install the pre-commit hook

Pre-commit hook

Our pre-commit hook formats and lints the code.

Formatting and linting

  • Run black admin_notice tests to format the code
  • Run flake8 admin_notice tests to lint the code

Testing

  • Run py.test --cov admin_notice tests to run the tests in the current Python env
  • Run tox to 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.

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

django-admin-notice-1.1.4.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

django_admin_notice-1.1.4-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file django-admin-notice-1.1.4.tar.gz.

File metadata

  • Download URL: django-admin-notice-1.1.4.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for django-admin-notice-1.1.4.tar.gz
Algorithm Hash digest
SHA256 5be29e74a89ef0a0da2bf6f4810c18b34b7baa3c5e1460651b32320d74e16c9c
MD5 50a1b2c73706490096b750ef890f7e30
BLAKE2b-256 74800b4de438a249e36ce4f4b75224b528c4e6a9429f9afb37d0a5e70480754c

See more details on using hashes here.

File details

Details for the file django_admin_notice-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: django_admin_notice-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for django_admin_notice-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fec06baeee4095f3e66fdbdb030e7a6bbc31f3e2f1775d068c6de0dd71ec5b50
MD5 975a4c179fa510338916a6cda5ff8af4
BLAKE2b-256 dd571ebb1db6e2568cb3212d0d05681531e16c314dfe7e9a428c0bcaea54a993

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page