如何在默认过滤器中使用 django 变量作为文本

发布于 2024-12-19 15:34:14 字数 271 浏览 0 评论 0原文

我有一个包含个人资料信息的字典,我用它来在 django 模板中显示个人资料详细信息。现在我想显示默认消息,以防特定信息不可用。 我知道我可以使用默认过滤器来完成此任务。但我所有的默认消息都存储为另一个字典。所以我想要这样的东西 -

<span>{{ profile.about|default:"{{ defaults.about }}" }}</span>

我无法使用上面的语法达到预期的结果。 任何有关正确方法的帮助将不胜感激。

I have a dictionary containing profile information which i am using to show profile details in django template. Now i want to display a default message in case a particular information is not available.
I know i can use default filter to accomplish this. But all my default messages are stored as another dictionary. so i want something like this -

<span>{{ profile.about|default:"{{ defaults.about }}" }}</span>

I am not able to achieve desired results using above syntax.
Any help on correct way will be really appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

烟若柳尘 2024-12-26 15:34:14
<span>{{ profile.about|default:defaults.about }}</span>
<span>{{ profile.about|default:defaults.about }}</span>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文