开发者

Rendering an iCal .ics file using Django: fixing incorrect newlines

开发者 https://www.devze.com 2023-03-30 16:49 出处:网络
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,

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').

0

精彩评论

暂无评论...
验证码 换一张
取 消