Reputation: 158
I am developing a flask-python application. I want to read a file and out put the content with line-breaks and white spaces intact. Below is the code I have now. But it outputs all the lines as a single stream without any line break. What is the correct way to do it?
with open(anupath, 'r')as f:
content=""
for line in f:
content += line + '\n'
Upvotes: 0
Views: 1455
Reputation: 47840
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 mimetype='text/plain'
on your flask Response
object before returning it:
return Response(content, mimetype='text/plain')
Upvotes: 1