title: How to print pretty JSON on a html page from a django template?
body: <p>Why is it that in python, I can pretty print JSON with the python example below, but in a django template, it doesn't work? How can I pretty print JSON in a django template?</p>
  
  <p>python:</p>
  
  <pre><code>import requests, json
  url = 'https://api.example.com/details'
  r = requests.get(url)
  json_data = r.json()
  json_pretty = json.dumps(json_data, sort_keys=True, indent=4)
  print (json_pretty)
  </code></pre>
  
  <p>django views.py:</p>
  
  <pre><code>def json_list(request):
      url = 'https://api.example.com/details'
      r = requests.get(url)
      json_data = r.json()
      json_pretty = json.dumps(json_data, sort_keys=True, indent=4)
  
      context = {
          "json_pretty": json_pretty,
          }
      return render(request, "json_output.html", context)
  </code></pre>
  
  <p>template:</p>
  
  <pre><code>&lt;div&gt;{{ json_pretty }}&lt;/div&gt;
  </code></pre>