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

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?)

You may use Markdown syntax here, but raw HTML will be removed.