使用Django渲染iCal .ics文件:修正不正确的换行符 [英] Rendering an iCal .ics file using Django: fixing incorrect newlines

查看:255
本文介绍了使用Django渲染iCal .ics文件:修正不正确的换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django的 render_to_response 来创建一个.ics文件,让人们下载。此.ics文件的原始内容正常,并在使用此工具时进行验证。但是,当我上传生成的文件时,我收到以下错误:

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:


您的日历正在使用无效的换行格式。确保使用\r\\\
来结束行而不是仅仅是\\\
(RFC 2445§4.1)。

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

是有没有办法获得 render_to_response \r\\\
作为换行符生成此页面,而不是仅仅 \\\
?我有一种感觉,这可能是一些低级的Python设置,我不能轻易地在Django中覆盖。

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 Template.render(上下文)。如果你自己调用了 Template.render ,它会返回一个字符串。所以你可以调用 string.replace('\\\
','\\\\
')

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

这篇关于使用Django渲染iCal .ics文件:修正不正确的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆