使用 Django 渲染 iCal .ics 文件:修复不正确的换行符

发布于 2024-12-01 05:26:02 字数 464 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哭泣的笑容 2024-12-08 05:26:02

render_to_responseTemplate.render(Context) 的快捷方式。如果您自己调用 Template.render,它将返回一个字符串。因此,您可以调用 string.replace('\n', '\r\n')。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文