Use wsgiref server since we use a single file application and not a scaffold that installs paste as a dependency. Explain step-by-step. Switch from print statements to JSON responses to keep the reader more focused to aspects of HTTP from curl and python calls. Slightly improve python program using a context manager and print response headers to have the response just like we have seen from curl.
The renderer implementation now offers overriding content type of response and does not fail if rows and headers are not passed to the renderer. Varying attributes of response like settings a filename is done in view code as considered best practice in pyramid docs. Both code samples are now more focused to the task, the view code in this recipe should not care much about the filename pattern. Fixed wrong code indentation as well. Added important links to pyramid documentation.