 <p>Your response is likely being treated as HTML by the browser, which collapses line breaks (among plenty of other things). If you want your file to be displayed as-is, set the parameter <code>mimetype='text/plain'</code> on your flask <code>Response</code> object before returning it:</p> <pre><code>return Response(content, mimetype='text/plain') </code></pre>