Created
November 28, 2017 22:10
-
-
Save tarkatronic/0b31eef92a74a4b2e2afd2176a5c9088 to your computer and use it in GitHub Desktop.
A Django jsonify template filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from django import template | |
from pygments import highlight | |
from pygments.formatters import HtmlFormatter | |
from pygments.lexers import get_lexer_by_name | |
register = template.Library() | |
@register.filter | |
def jsonify(value): | |
lexer = get_lexer_by_name('json', stripall=True) | |
formatter = HtmlFormatter() | |
return highlight(json.dumps(value, indent=2), lexer, formatter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment