1

I am trying to return a file download directly from a view, which works fine on Mac OS, except when I run this from a Windows OS (from the browser), the file does not have the 3 lines, but just 1.. Is there a solution for this, I have read a lot of articles about cross os issues, but none seem to have a solution covered

template (pseudo code, notice 3 lines, on windows this is downloaded as a single line)

%DO% script/{foo}.sh --var={bar}
%END%
some,comma,separated,stuff

view

def view(self, request, **kwargs):
    file_name = 'test.txt'

    template = render_to_string('templates/test.txt', {  # <= template
        "foo": "hello",
        "bar": "world"
    })

    resp = HttpResponse(template, content_type='application/force-download')
    resp['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)

    return resp
Bea Trix
  • 75
  • 1
  • 7
  • 2
    maybe this could help you http://stackoverflow.com/questions/6373888/converting-newline-formatting-from-mac-to-windows – Lawrence Benson Sep 01 '15 at 14:31
  • Windows newlines are CR LF. OSX newlines are LF. You can try editing the template to have Windows newlines. – Artur Gaspar Sep 01 '15 at 14:36
  • @LawrenceBenson thanks, I am trying to find a python only solution I don't want to use _sed_ or any command line processes, at best not even open() as I would have to create a file.. I am happy with just Windows support, but the server will be linux – Bea Trix Sep 01 '15 at 14:38
  • @ArturGaspar, thanks seems viable, now I just need to find out how – Bea Trix Sep 01 '15 at 14:39
  • @BeaTrix The question linked by Lawrence Benson shows how to. You just need to run it once on the template files. – Artur Gaspar Sep 01 '15 at 14:43

0 Answers0