django-tables2 linkColumn 外部 url

2023-12-05

我有 2 个模型属性 - model.name 和 model.url 我需要创建一个 linkColumn ,该列名称 = model.name 并链接到中指定的 url 型号.url

有可能实现这样的目标吗?

thanks


您可以使用 TemplateColumn 来实现它。你的tables.py应该看起来像这样

# yourapp/tables.py
import django_tables2 as tables
from yourapp.models import yourmodel
class YourTable(tables.Table):
    name = tables.TemplateColumn('<a href="{{record.url}}">{{record.name}}</a>')
    class Meta:
        model = yourmodel
        fields = ('name') # fields to display

您可以参考DOC,了解更多信息。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

django-tables2 linkColumn 外部 url 的相关文章

随机推荐