django-prettyjson is a Django library that provides a pretty JSON viewer for Django forms, admin, and templates. It's built upon jQuery JSONView and is compatible with various JSON storage methods, including raw JSON strings, Django's `JSONField` (from `django.contrib.postgres` or `django-jsonfield`), and any Python object serializable to JSON via `standardjson`. The current version is 0.4.1, and while the last code push was 9 months ago, the last official release was in 2018, indicating a maintenance release cadence.
pip install django-prettyjsonVerified import paths — ran on the pinned version, not inferred.
To use `django-prettyjson`, add 'prettyjson' to your `INSTALLED_APPS`. For forms and the Django admin, import `PrettyJSONWidget` and assign it to a `JSONField`'s widget. In templates, load the `prettyjson` tags, include `{% prettyjson_setup %}` in your head block (or similar), and then use `{% prettyjson your_data %}` to display JSON objects or strings beautifully.
Use `{% prettyjson_setup jquery=False %}` in your templates if jQuery is already present.Set `PrettyJSONWidget(attrs={'initial': 'parsed'})` in your form or `formfield_overrides`.For read-only fields, consider custom admin display methods or a different approach for pretty-printing, potentially involving a custom template or JavaScript.
Review the GitHub issue for potential workarounds or consider if this bug affects your specific Django/Python/PostgreSQL versions. Testing this behavior is recommended.
Add `'prettyjson'` to the `INSTALLED_APPS` tuple in your `settings.py` file.
Add `{% load prettyjson %}` at the top of your Django template file where you intend to use the tags.Ensure custom template tags adhere to Django's parsing function signature (e.g., `def do_my_tag(parser, token):`) and correctly handle `token.split_contents()` and return a `Node` instance.
No dependency data recorded yet.