render_to_json

1
2
3
4
5
6
7
8
9
frm django.shortcuts import render_to_response

def render_to_json(*args, **kwargs):
    response = render_to_response(*args, **kwargs)
    response['mimetype'] = "text/javascript"
    response['Pragma'] = "no cache"
    response['Cache-Control'] = "no-cache, must-revalidate"

    return response

More like this

  1. CSV to JSON Fixture by briangershon 4 years, 8 months ago
  2. Breaking tests.py into multiple files by gsakkis 4 years ago
  3. Format transition middleware by limodou 7 years, 1 month ago
  4. Custom model field to store dict object in database by rudyryk 4 years ago
  5. JSONField by deadwisdom 6 years, 8 months ago

Comments

kcarnold (on February 28, 2008):

JSON doesn't necessarily mean no cache. Don't blindly copy-paste; think about if your data can be cached.

#

(Forgotten your password?)