[Django]-How add tag to pandas dataframe.to_html links so that absolute path of url will not shown in the html but a tag instead?

8👍

found it , using apply function to create href without td like this :

df_products['id'] = df_products['id'].apply(create_clickable_id)
def create_clickable_id(id):
    url_template= '''<a href="../../link/to/{id}" target="_blank">{id}</a>'''.format(id=id)
    return url_template

and the most important is to add escape=False to pandas to_html method

df_products = df_products.to_html(index=False, table_id="sellers_table-id", render_links=True,escape=False)

Leave a comment