[我正在尝试向表中的所有行添加'编辑'按钮,为此我正在使用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>')
如您所见,它显示一个'-'而不是按钮。
我的问题是代码在Meta之下而不是在类之下,这解决了我的问题!