Skip to main content

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+

License

MIT

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_json_highlight-0.1.0.tar.gz (3.7 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_json_highlight-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file django_admin_json_highlight-0.1.0.tar.gz.

File metadata

  • Download URL: django_admin_json_highlight-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","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

Hashes for django_admin_json_highlight-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9916fb15a3c6385babbb610ebd28d0fe7abb77b4b5dcfccb95a99cb64881e76b
MD5 3d3a7f7c37cf82e4af38897c204c0a1e
BLAKE2b-256 189f3bcea946035a7da7e876544123dbbeca7629751c4c6e315ba57fe1ad1146

See more details on using hashes here.

File details

Details for the file django_admin_json_highlight-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_admin_json_highlight-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","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

Hashes for django_admin_json_highlight-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1513c1f5ef27e9936003f3205595b56aa6aac0605ce3e95974de39afeb494ee4
MD5 cd16709168f19841dbcf938d7bf7bf7a
BLAKE2b-256 126378c78dc927c87bcc1e389b022a63db04768e94a62a83c984845a124cc0eb

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