Created
August 11, 2020 02:15
-
-
Save 0xregulus/9a587061eb30fd5c5ef45f76e8f81908 to your computer and use it in GitHub Desktop.
Useful Django template filters for handling JSON and for pretty print JSON in templates
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 | |
register = template.Library() | |
@register.filter | |
def loadjson(data): | |
return json.loads(data) | |
@register.filter | |
def prettyjson(data): | |
return json.dumps(json.loads(data), indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment