0

Hi I am using django and following the below method in views.py to return a output file,

response = HttpResponse(content=log_file)
response['Content-Type'] = 'application/txt:html'
return HttpResponse(response)

Now the issue is when I return the file in browser is displayed without /n (next line)

my actual file content is,

../xyz/value.txt
../abc/cls.txt
../opt/value.txt
../zz.txt

But it is display as,

../xyz/value.txt ../abc/cls.txt ../opt/value.txt ../zz.txt

when I open the same file with vim editor in linux machine it displays properly but here when I return from views and read it in browser it shows without /n

How can I fix this issue?

Håken Lid
  • 22,318
  • 9
  • 52
  • 67
Naggappan Ramukannan
  • 2,564
  • 9
  • 36
  • 59

1 Answers1

0

StreamingHttpResponse response from djanto.http solved the issue as below,

from django.http import StreamingHttpResponse

@csrf_exempt
def display_text(request):
    content = open(log_file).read()
    response = StreamingHttpResponse(content)
    response['Content-Type'] = 'text/plain; charset=utf8'
    return response     
Naggappan Ramukannan
  • 2,564
  • 9
  • 36
  • 59