【发布时间】:2011-12-17 05:33:12
【问题描述】:
我无法在 Django 中执行以下操作:
{% include "admin/includes/pager.html" with title_pager="{{myobject.title}}" %}
或
{% include "admin/includes/pager.html" with title_pager="{{myobject}}" %}
解决方法是什么?
【问题讨论】:
我无法在 Django 中执行以下操作:
{% include "admin/includes/pager.html" with title_pager="{{myobject.title}}" %}
或
{% include "admin/includes/pager.html" with title_pager="{{myobject}}" %}
解决方法是什么?
【问题讨论】:
您不需要在模板标签中将参数括在{{ }} 括号中。
如果它是一个变量,而不是一个字符串,那么不要使用"" 引号。
以下应该有效:
{% include "admin/includes/pager.html" with title_pager=myobject.title %}
{% include "admin/includes/pager.html" with title_pager=myobject %}
有关更多信息,请参阅include tag 的 Django 文档。
【讨论】:
include 文档给出了一个包含多个变量的示例。如果您在阅读后仍然卡住,请打开一个新问题。
{% include "name_snippet.html" with person="Jane" greeting="Hello" %}
{%include "bla.html" with var=value %} 在一行中。