是否可以将模板标签应用于< td>当使用django-tables2? [英] Is it possible to apply a template tag to a <td> when using django-tables2?
问题描述
我正在使用django-tables2为我创建我的表。我需要将模板标签应用于其中一个列中的每个单元格()。通过创建自定义表格布局,只需将模板标签应用于一列,似乎需要额外的努力。有没有办法在django-tables2中这样做?
I am using django-tables2 to create my table for me. I need to apply a template tag to each of the cells () in one of the columns. It seems like alot of extra effort to go through and create a custom table layout just to apply the template tag to the one column. Is there a way to do this in django-tables2?
更新:
我可能没有解释什么我正在寻找足够好的我不相信会奏效。
I may not have explained what I'm looking for well enough. I don't believe that will work.
我的代码:
class CombineTable(tables.Table):
build_no = tables.LinkColumn('run', args=[A('release'), A('id')], verbose_name="Build")
flavor = tables.Column(verbose_name="Flavor")
pass_rate_pct = tables.Column(verbose_name="Image Pass Rate")
我希望pass_rate_pct中的每一个都使用class()中的模板标签{{pass_rate_color}},其中pass_rate_color根据pass_rate_pct的输出输出一个特定的样式。
I want each in pass_rate_pct to use the template tag {{pass_rate_color}} in the class () where pass_rate_color then outputs a particular style based upon what the output of pass_rate_pct is.
推荐答案
django_tables2允许您指定用于输出表的替代自定义模板。拿一个 django_tables2 / templates / django_tables2 / table.html
的副本,并重命名它。 table_pass_rate.html
并在第29行输入您的标签:
django_tables2 allows for you to specify an alternative custom template for outputting your tables. Take a copy of django_tables2 / templates / django_tables2 / table.html
and rename it e.g. table_pass_rate.html
and enter your tag on line 29:
{% pass_rate_color cell %}
现在生成表使用:
{% render_table table "table_pass_rate.html" %}
See the django_tables2 code for tags and the template for more info.
这篇关于是否可以将模板标签应用于< td>当使用django-tables2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!