django-tables2 linkColumn外部网址 [英] django-tables2 linkColumn external url

查看:60
本文介绍了django-tables2 linkColumn外部网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have 2 model attributes - model.name and model.url I need to create a linkColumn that column name = model.name and link to the url specified in model.url

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

Is it possible to achieve such thing?

谢谢

推荐答案

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

You can use TemplateColumn to achieve it. Your tables.py should look something like this

# 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 ,以获取更多信息。

You may refer to the DOC, for more info.

这篇关于django-tables2 linkColumn外部网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆