diff options
-rw-r--r-- | pecan/core.py | 4 | ||||
-rw-r--r-- | pecan/tests/test_base.py | 13 |
2 files changed, 16 insertions, 1 deletions
diff --git a/pecan/core.py b/pecan/core.py index 44bad0e..eb3fe69 100644 --- a/pecan/core.py +++ b/pecan/core.py @@ -526,7 +526,9 @@ class PecanBase(object): template = content_types.get(pecan_state['content_type']) # check if for controller override of template - template = pecan_state.get('override_template', template) + template = pecan_state.get('override_template', template) or ( + 'json' if self.default_renderer == 'json' else None + ) pecan_state['content_type'] = pecan_state.get( 'override_content_type', pecan_state['content_type'] diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index 81471ec..c076139 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -1520,6 +1520,19 @@ class TestEngines(PecanTestCase): assert r.status_int == 200 assert b_("<h1>Hello, Jonathan!</h1>") in r.body + def test_default_json_renderer(self): + + class RootController(object): + @expose() + def index(self, name='Bill'): + return dict(name=name) + + app = TestApp(Pecan(RootController(), default_renderer='json')) + r = app.get('/') + assert r.status_int == 200 + result = dict(json.loads(r.body.decode())) + assert result == {'name': 'Bill'} + class TestDeprecatedRouteMethod(PecanTestCase): |