使用 Django 渲染 iCal .ics 文件:修复不正确的换行符
我正在使用 Django 的 render_to_response
动态创建一个 .ics 文件以供人们下载。此 .ics 文件的原始内容很好,并且在我使用此工具时进行验证。但是,当我上传生成的文件时,出现以下错误:
您的日历使用了无效的换行格式。确保使用 \r\n 来结束行,而不仅仅是 \n (RFC 2445 §4.1)。
有没有办法让 render_to_response
生成此页面,并使用 \r\n
作为换行符,而不仅仅是 \n
?我有一种感觉,这可能是一些低级的 Python 设置,我无法在 Django 中轻松覆盖。
还考虑了明智的替代解决方案!谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
render_to_response
是Template.render(Context)
的快捷方式。如果您自己调用Template.render
,它将返回一个字符串。因此,您可以调用 string.replace('\n', '\r\n')。render_to_response
is a shortcut forTemplate.render(Context)
. If you calledTemplate.render
yourself, it would return a string. So you could then callstring.replace('\n', '\r\n')
.