Skip to main content

Show a floating notice banner above the Django admon interface

Project description

Django Admin Notice

PyPI PyPI - Python Version PyPI - Django Version Downloads Codecov License

Show a floating notice banner above the Django admin interface. Particularly useful for indicating the current deployment environment.

Admin notice preview (light mode) Admin notice preview (dark mode)

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:

  1. poetry install
  2. poetry run python tests/project/manage.py migrate
  3. poetry run python tests/project/manage.py createsuperuser
  4. 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

django_admin_notice-2.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file django_admin_notice-2.1.0.tar.gz.

File metadata

  • Download URL: django_admin_notice-2.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.4.12-arch1-1

File hashes

Hashes for django_admin_notice-2.1.0.tar.gz
Algorithm Hash digest
SHA256 333a5eb1cc60154e298d8805c1f834a83828c8d90eafa30eb7a7916fe7ab7587
MD5 2515bba0f8062b5ca8886bfcf6a58b52
BLAKE2b-256 46ed0005e9535106bd73b2dd13e5c1af2f37b90147e67fcd71c52cde985af10a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_admin_notice-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.4.12-arch1-1

File hashes

Hashes for django_admin_notice-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc8f9987733173537e86ccc3f91b09e0c80a625c114ecd2ee9cea2cc7810d088
MD5 fa2c014a876d3c549f32aa4890c36f3c
BLAKE2b-256 d1552f6b04a28072e4c5cea567303f72b7b35f619c0e0826eff2a139c6ee6a6b

See more details on using hashes here.

Supported by

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