Django table2自定义列未呈现

问题描述 投票:0回答:1

[我正在尝试向表中的所有行添加'编辑'按钮,为此我正在使用TemplateColumn,它根本不会在表中呈现按钮。

这是我正在尝试的:

tables.py

from django_tables2 import tables, TemplateColumn
from .models import Conductores


class ConductoresTable(tables.Table):
    class Meta:
        model = Conductores
        template_name = "django_tables2/bootstrap-responsive.html"
        fields = ("nombres", "apellidos", "telefono", "edad", "ine", 'edit')
        attrs = {"class": "table table-hover table-sm"}
        edit = TemplateColumn(
            '<a class="btn btn btn-info btn-sm" href="{% url "conductor_edit" record.id %}">Editar</a>')

this is how it looks at the moment

如您所见,它显示一个'-'而不是按钮。

django-tables2
1个回答
0
投票

我的问题是代码在Meta之下而不是在类之下,这解决了我的问题!

© www.soinside.com 2019 - 2024. All rights reserved.