Skip to content

Instantly share code, notes, and snippets.

@pablorecio
Last active December 17, 2015 22:49
Show Gist options
  • Save pablorecio/5685144 to your computer and use it in GitHub Desktop.
Save pablorecio/5685144 to your computer and use it in GitHub Desktop.
Really basic AJAXResponseMixin for being used as a Mixin on Django's Class Based Views
class AJAXResponseMixin(object):
def get(self, request, *args, **kwargs):
response = super(AJAXResponseMixin, self).get(request, *args, **kwargs)
if self.request.is_ajax():
return HttpResponse(json.dumps({
'response': response.status_code,
'location': response['Location'],
# whatever else you want to return
}), mimetype='application/json')
else:
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment