将django-tables2中行的属性设置为record.id

时间:2015-02-27 10:54:23

标签: django-tables2

我正在尝试将django-tables2中一行的属性设置为当前记录的id。

为此,我以这种方式修改了table.html模板中的一行:

<tr row_id="{{ record.id }}" class="{{ forloop.counter|divisibleby:2|yesno:"even,odd" }}">

但是这给了我空的row_id =&#34;&#34;在HTML结果中。有什么问题?

1 个答案:

答案 0 :(得分:0)

django-tables2 table.html的for变量的默认名称(正如我们在https://github.com/bradleyayers/django-tables2/blob/master/django_tables2/templates/django_tables2/table.html#L25看到的)是row(而不是record,用于{{ 1}})。

您尚未共享TemplateColumn模板,但我认为这可能是您看到空table.html的原因。那么您可以尝试将row_id更改为row_id="{{ record.id }}"吗?