def get_prettyjson_html(api_key):
boite = get_object_or_404(Boite, api_key=api_key)
# Example from https://www.pydanny.com/pretty-formatting-json-django-admin.html
response = json.dumps(boite.get_apps_dictionary(), sort_keys=True, indent=2)
response = response[:5000]
formatter = HtmlFormatter(style='friendly')
response = highlight(response, JsonLexer(), formatter)
style = "<style>" + formatter.get_style_defs() + "</style><br>"
return mark_safe(style + response)
评论列表
文章目录