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

杀马特。学长 韩版系。学妹 提交于 2019-12-25 13:18:21

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/7177865/rendering-an-ical-ics-file-using-django-fixing-incorrect-newlines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!