Skip to content

Instantly share code, notes, and snippets.

@0xregulus
Created August 11, 2020 02:15
Show Gist options
  • Save 0xregulus/9a587061eb30fd5c5ef45f76e8f81908 to your computer and use it in GitHub Desktop.
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
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