Custom content type for json renderer

34 views
Skip to first unread message

Vlad K.

unread,
Nov 10, 2012, 10:09:08 AM11/10/12
to pylons-...@googlegroups.com

Hello list,

I'm trying to use the built-in json renderer to produce a json formatted
response, but if I set the response content type to anything else,
despite of explicitly naming the renderer via view_config, the response
body is empty:


@view_config(route_name="test", request_method="POST", renderer="json")
def test_view(request)
request.response.content_type = "application/vnd.myformat+json"
return {"test" : "testing"}


The content type (and any other response header) is set properly, but
the body is empty. I suppose I can "manually" produce the json output
with a string renderer and some json.dumps() magic.

But is this expected? I haven't checked the internals, but I'd expect
the renderer to set default content type before the view callable is
executed and expect it to return a value which is JSON-serializeable,
regardless of what response headers does the callable set.

Thanks.


Vlad K.

unread,
Nov 10, 2012, 10:14:37 AM11/10/12
to pylons-...@googlegroups.com

My bad for failing to mention that this is Pyramid 1.4a3.
Reply all
Reply to author
Forward
0 new messages