
Research
/Security News
npm Author Qix Compromised via Phishing Email in Major Supply Chain Attack
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Enables pretty JSON viewer in Django forms, admin, or templates. The viewer is adapted from jQuery JSONView. It is compatible with almost anything: JSON stored in a string, a jsonfield (using django.contrib.postgres or django-jsonfield), or any python object that can be serialized to JSON (using standardjson).
See http://kevinmickey.github.io/django-prettyjson
At the command line:
pip install django-prettyjson
Add 'prettyjson'
to INSTALLED_APPS
in settings.py
:
INSTALLED_APPS = (
...,
'prettyjson',
)
In a form or admin of a model, enable a pretty JSON viewer for a particular field:
from prettyjson import PrettyJSONWidget
class JsonForm(forms.ModelForm):
class Meta:
model = Test
fields = '__all__'
widgets = {
'myjsonfield': PrettyJSONWidget(),
}
class JsonAdmin(admin.ModelAdmin):
form = JsonForm
Enable pretty JSON viewer for every JSONField of a model:
from django.contrib.postgres.fields import JSONField
class JsonAdmin(admin.ModelAdmin):
formfield_overrides = {
JSONField: {'widget': PrettyJSONWidget }
}
In templates, you can also enable a pretty JSON viewer. Use the prettyjson
template tag with a string JSON or with objects (dicts, QuerySets, etc.) that can be serialized to a JSON. Note that the template tag must be loaded using {% load prettyjson %}
. It also has CSS and JS that must be included using {% prettyjson_setup %}
.
{% extends "base.html" %}
{% load prettyjson %}
{% block header %}
{{ block.super }}
{% prettyjson_setup %}
{% endblock %}
{% block content %}
{% prettyjson myqueryset %}
{% prettyjson mydict %}
{% prettyjson '{"hey": "guy","anumber": 243,"anobject": {"whoa": "nuts","anarray": [1,2,"thr<h1>ee"], "more":"stuff"},"awesome": true,"bogus": false,"meaning": null, "japanese":"明日がある。", "link": "http://jsonview.com", "notLink": "http://jsonview.com is great"}' %}
{% prettyjson '{}' %}
{% endblock %}
The setup includes jQuery, loaded as django.jQuery to avoid namespace conflict. If your page already includes jQuery, use {% prettyjson_setup jquery=False %}
to avoid loading jQuery a second time.
By default the jsonwidget will render as a raw string with a button to click to change it to parsed json. For it to render as parsed json initially, you can pass an argument:
class JsonAdmin(admin.ModelAdmin):
formfield_overrides = {
JSONField: {'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})}
}
Or, in a template tag:
{% prettyjson mydict initial='parsed' %}
In development.
source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements-test.txt
(myenv) $ python runtests.py
Dependencies, parts of code, and/or sources of inspiration:
Tools used in developing, testing, and/or rendering this package:
0.1.0 (2016-05-28) ++++++++++++++++++
0.2.0 (2016-05-29) ++++++++++++++++++
0.2.1 (2016-07-01) ++++++++++++++++++
0.2.2 (2016-12-07) ++++++++++++++++++
0.3.0 (2017-05-23) ++++++++++++++++++
0.3.1 (2018-04-01) ++++++++++++++++++
0.3.2 (2018-04-09) ++++++++++++++++++
0.3.3 (2018-04-13) ++++++++++++++++++
0.4.0 (2018-04-30) ++++++++++++++++++
0.4.1 (2018-08-07) ++++++++++++++++++
FAQs
Enables pretty JSON viewer in Django forms, admin, or templates
We found that django-prettyjson demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.