[Django]-Django: In django-tables2 how to modify the way URLField gets rendered

0👍

a little late answer, but you should change your PersonTable class like this:


class PersonTable(django_tables2.Table):
    personal_webpage = CustomTextLinkColumn('my_app.views.personal_page_view', 
        args=[A('personal_webpage')], custom_text='Personal Webpage', 
        verbose_name='Personal Webpage', )

    class Meta: 
        model = Person

The important (and not very clear) thing thing to keep in mind is that “render methods are only called if the value for a cell is determined to be not an empty value”. Since your model does not have a webpage_link field or attribute, there’s no value given to it. So you can either change the name to personal_webpage as I propose or pass the empty_values=() to your Column init as proposed in the answer to this question: Django Tables adding a LinkColumn / NoReverseMatch Error

Leave a comment