Django 传递对象以包含 [英] Django pass object to include

查看:20
本文介绍了Django 传递对象以包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在 Django 中执行以下操作:

I cannot do the following in Django:

{% include "admin/includes/pager.html" with title_pager="{{myobject.title}}" %}

{% include "admin/includes/pager.html" with title_pager="{{myobject}}" %}

解决方法是什么?

推荐答案

你不需要在模板标签中用 {{ }} 括号括起参数.

You do not need to surround arguments in {{ }} brackets in template tags.

如果它是一个变量,而不是一个字符串,那么不要使用 "" 引号.

If it's a variable, not a string, then do not use "" quotes.

以下应该有效:

{% include "admin/includes/pager.html" with title_pager=myobject.title %}

{% include "admin/includes/pager.html" with title_pager=myobject %}

请参阅 Django 文档中的 include 标签更多信息.

See the Django docs for the include tag for more information.

这篇关于Django 传递对象以包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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