Last active
December 17, 2015 22:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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