I’m using Django’s render_to_response to create an .ics file on the fly for people to download. The raw content of this .ics file is fine, and validates when I use this tool. However, when I upload the file that is generated, I get this error:
Your calendar is using an invalid newline format. Make sure to use \r\n to end lines rather than just \n (RFC 2445 §4.1).
Is there any way to get render_to_response to generate this page with \r\n as newlines, instead of just \n? I’ve got the feeling that this will probably be some low-level Python setting, that I can’t easily override in Django.
Sensible alternative solutions also considered! Thanks.
render_to_responseis a shortcut forTemplate.render(Context). If you calledTemplate.renderyourself, it would return a string. So you could then callstring.replace('\n', '\r\n').