Is there a way to get the json handler for Pyramid to output formatted, fairly printed output?

I like that my json output is well formatted even for the REST API. This helps with debugging, etc. Extra overhead is minimal, especially when using gzip

Anyway, to tell the jony pyramid to the renderer (i.e. this thing)

@view_config(request_method='POST', renderer='json') 

to output formatted, fairly printed output?

+6
source share
1 answer

I just figured it out myself. In my init, I added

  from pyramid.renderers import JSON # ... config.add_renderer('prettyjson', JSON(indent=4)) 

and then I just do it in my opinion

  @view_config(request_method='POST', renderer='prettyjson') 
+9
source

Source: https://habr.com/ru/post/950855/


All Articles