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_response
is a shortcut for Template.render(Context)
. If you called Template.render
yourself, it would return a string. So you could then call string.replace('\n', '\r\n')
.
精彩评论