From e5472a6fae7629260b9a9e56c137523e36d5dd36 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 4 Jun 2019 12:15:32 -0500 Subject: [PATCH] Add `json_response()` convenience method for all views er, class-based views anyway --- tailbone/views/core.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tailbone/views/core.py b/tailbone/views/core.py index 45047c7b..57dcf5aa 100644 --- a/tailbone/views/core.py +++ b/tailbone/views/core.py @@ -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