Login

Tag "jsonp"

Snippet List

JSON decorator for views handling ajax requests

Sample usage for using decorator `@json_response(ajax_required=True, login_required=True)` `def subscribe(request):` ` return {"status":"success"}` Converts a function returning dict into json response. Does is_ajax check and user authenticated check if set in flags. When function returns HttpResponse does nothing.

  • ajax
  • json
  • decorator
  • jsonp
Read More

Django JSONP Decorator

This decorator function wraps a normal view function so that it can be read through a jsonp callback. Usage: @AllowJSONPCallback def my_view_function(request): return HttpResponse('this should be viewable through jsonp') It looks for a GET parameter called "callback", and if one exists, wraps the payload in a javascript function named per the value of callback. Using AllowJSONPCallback implies that the user must be logged in (and applies automatically the login_required decorator). If callback is passed and the user is logged out, "notLoggedIn" is returned instead of a normal redirect, which would be hard to interpret through jsonp. If the input does not appear to be json, wrap the input in quotes so as not to throw a javascript error upon receipt of the response.

  • jsonp
  • jsonp-decorator
Read More

2 snippets posted so far.