A simple Django Admin mixin to highlight JSONB fields using highlight.js
Project description
django-admin-json-highlight
A simple Django Admin mixin to render and syntax-highlight JSON / JSONField values using highlight.js.
Installation
pip install django-admin-json-highlight
Add to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"django_admin_json_highlight",
]
Usage
Mix JsonHighlightMixin into your ModelAdmin and use render_json_field to
produce HTML for any JSON-serializable attribute on the object.
from django.contrib import admin
from django_admin_json_highlight import JsonHighlightMixin
from .models import Event
@admin.register(Event)
class EventAdmin(JsonHighlightMixin, admin.ModelAdmin):
readonly_fields = ("payload_pretty",)
def payload_pretty(self, obj):
return self.render_json_field(obj, "payload")
payload_pretty.short_description = "Payload"
Configuration
The mixin loads highlight.js from cdnjs by default. Override either URL in
settings.py to use a different version, theme, or self-hosted asset:
HIGHLIGHT_JS_JS_URL = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"
HIGHLIGHT_JS_CSS_URL = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/github-dark.min.css"
Relative paths are resolved through Django's static tag, so you can also point
these at files served from your own STATICFILES_DIRS.
Requirements
- Python 3.10+
- Django 4.2+
Development
Install dev dependencies:
uv sync --dev
Run the test suite against the active interpreter:
uv run pytest
Matrix testing with nox
noxfile.py defines a Django × Python matrix matching CI. Nox provisions
interpreters via uv, so you do not need to install each Python version
manually.
List sessions:
uv run nox --list
Run the full matrix:
uv run nox
Run a single combination:
uv run nox -s "tests(python='3.13', django='6.0')"
Pass extra arguments through to pytest with --:
uv run nox -s "tests(python='3.13', django='6.0')" -- -k test_media -x
License
MIT
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_admin_json_highlight-0.1.1.tar.gz.
File metadata
- Download URL: django_admin_json_highlight-0.1.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.9 {"installer":{"name":"uv","version":"0.11.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee9742870ff3d26dcf6881005a61249afe4457cded111a8d4b5973c535bbce22
|
|
| MD5 |
6b13dcf93de72074e1782f84d422de54
|
|
| BLAKE2b-256 |
4ec4d57788dc2a5474403e381acda516e6fc846d50eda571fc9e58ef06844a66
|
File details
Details for the file django_admin_json_highlight-0.1.1-py3-none-any.whl.
File metadata
- Download URL: django_admin_json_highlight-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.9 {"installer":{"name":"uv","version":"0.11.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
673bee5fc6e327a71e3e0d82d64c79cb0648837fd387d8a4f77a01e3dbacce1c
|
|
| MD5 |
fdba589b84f00c49088332b1a61b0a8b
|
|
| BLAKE2b-256 |
cab8249170b9617599ba4d1f8e182c8360b30f9413ad900e99eeecf55f571911
|