django-inject-message
Inject HTML messages into Django HTTP responses based on URL patterns, anchor sequences, and activity rules.
Purpose
Manage banners, alerts, and notices from the database (or admin) without editing templates. Messages are inserted into rendered HTML responses by middleware after matching:
- URL path patterns
- Anchor sequences in the HTML body (e.g.
<body>,</header>) - Activity window (
active_from/active_until) - Optional cron schedule (weekends, business hours, etc.)
- Severity level with built-in CSS styling
Installation
pip install django-inject-message
Add to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"django_boosted",
"inject_message",
]
Add middleware (before compression middleware if you use GZip):
MIDDLEWARE = [
# ...
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django_boosted.middleware.CurrentUserMiddleware",
"inject_message.middleware.InjectMessageMiddleware",
]
Run migrations:
python manage.py migrate inject_message
Quick start
1. Create a message and injection rule
from inject_message.models import Message, MessageInjection, MessageLevel
message = Message.objects.create(
label="Maintenance",
content="<strong>Scheduled maintenance tonight at 22:00.</strong>",
level=MessageLevel.WARNING,
)
MessageInjection.objects.create(
message=message,
url_pattern="/dashboard/",
after_sequence="<body>",
)
2. Or use the Django admin
Open /admin/ and manage Messages with inline Message injections. Each message supports:
- Content and severity level (
debug,info,success,warning,error) - Activity dates and cron schedule (with presets for weekends / weekdays)
- Multiple injection rules per message
3. Schedule examples
from inject_message import SCHEDULE_WEEKENDS, SCHEDULE_WEEKDAYS, SCHEDULE_BUSINESS_HOURS
Message.objects.create(
label="Weekend promo",
content="Special offer this weekend!",
level=MessageLevel.SUCCESS,
schedule=SCHEDULE_WEEKENDS,
)
Cron format: minute hour day month weekday (e.g. * * * * 0,6 for weekends).
Demo (development)
This repository includes a demo app under tests/demo/:
| URL | Scenario |
|---|---|
/demo/single/ |
One message |
/demo/multiple/ |
Several messages |
/demo/multiple-places/ |
One message, multiple anchors |
Seed demo data:
PYTHONPATH=src python manage.py seed_demo_messages --clear
PYTHONPATH=src python manage.py runserver
Security
Message content is injected as HTML. Only trusted staff should edit messages in the admin.
Development
PYTHONPATH=src python -m pytest tests/ -v
PYTHONPATH=src python manage.py migrate
License
MIT
Metadata
Release files for django-inject-message 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_inject_message-0.1.0.tar.gz | 12.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_inject_message-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.4 kB
Release files / django_inject_message-0.1.0.tar.gz
| Download URL | django_inject_message-0.1.0.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6e1cfb221f25f60cf9134e0ff27dba8c6a27bf1cea6af5fa3bc1325ffb806d5
|
|
BLAKE2b-256 checksum How to use checksums |
e193e32ab24b666c9714d8ca2fa6b61b2450d454eac9638ffb9df43545c0ff77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / django_inject_message-0.1.0-py3-none-any.whl
| Download URL | django_inject_message-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3df6db5f091d6f032b94b5d1c2eeb0e21bae0787c02418740f4a24e563e07180
|
|
BLAKE2b-256 checksum How to use checksums |
d0f2054d35d000c0f7ae44574de3442314104edd7e9e31c36248eab24a3c07b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for django-inject-message 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.