Add json_response() convenience method for all views

er, class-based views anyway
This commit is contained in:
Lance Edgar 2019-06-04 12:15:32 -05:00
parent e06f8c16df
commit e5472a6fae

View file

@ -111,6 +111,13 @@ class View(object):
kwargs.setdefault('can_cancel', True)
return render_to_response(template, kwargs, request=self.request)
def json_response(self, data):
"""
Convenience method to return a JSON response.
"""
return render_to_response('json', data,
request=self.request)
def file_response(self, path):
"""
Returns a generic FileResponse from the given path