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?
Update:
I may not have explained what I'm looking for well enough. I don't believe that will work.
My code:
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")
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.
The template tags are a way of telling Django that here comes something else than plain HTML. The template tags allows us to to do some programming on the server before sending HTML to the client.
Django offers a variety of built-in template tags such as {% if %} or {% block %}. However, Django also allows you to create your own template tags to perform custom actions. The power of custom template tags is that you can process any data and add it to any template regardless of the view executed.
What is URL Template Tag? The URL template tag is a typical type of Tag in the Django Template Language framework. This tag is specifically used to add View URLs in the Template Files.
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 %}
Now when generating the table use:
{% render_table table "table_pass_rate.html" %}
See the django_tables2 code for tags and the template for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With