Skip to content

Instantly share code, notes, and snippets.

@reedobrien
Created March 21, 2011 12:44
Show Gist options
  • Save reedobrien/879395 to your computer and use it in GitHub Desktop.
Save reedobrien/879395 to your computer and use it in GitHub Desktop.
A jsonp renderer for pyramid
## from http://pastie.org/1695550
def JsonPRendererFactory(info):
"""A special renderer which returns JSONP data.
Be careful to only return data that can be dumped to JSON. In particular
unicode strings may not work.
"""
def render(value, system):
request=system.get("request")
callback=request.params["callback"]
request.response_content_type="application/json"
return "%s(%s)" % (callback, json.dumps(value))
return render
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment