将变量传递给 django 自定义模板标签

发布于 2024-10-09 01:18:30 字数 443 浏览 0 评论 0原文

我正在使用 django-profiles。在我的 profile_detail 模板中,我知道我将收到一个 profile 变量。

我想制作一个自定义标签,通过用户 ID 获取每个用户的内容。像这样:

{% get_user_content book.review profile.user.id as review_list %}

但是,当我的解析器运行时,似乎 profile.user.id 没有转换为 id 号并引发异常。

我可以通过将 profile.user.id 更改为 1(表示管理员)来验证我的自定义标签是否有效。

{% get_user_content book.review 1 as review_list %}

以前有人处理过吗?你做了什么?

Im using django-profiles. In my profile_detail template I know that I will receive a profile variable.

I want to make a custom tag that gets the content per user via user id. Like this:

{% get_user_content book.review profile.user.id as review_list %}

However, when my parser runs It seems like profile.user.id was not transformed to an id number and throws an exception.

I can verify that my custom tag works by changing profile.user.id to say 1 for admin.

{% get_user_content book.review 1 as review_list %}

Has anyone deals with it before? What did you do?

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

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

发布评论

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

评论(1

想念有你 2024-10-16 01:18:30

模板标签从不翻译参数。您需要自己在上下文中进行查找。

Template tags never translate arguments. You need to do the lookup in the context yourself.

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