Search code examples
pythonhtmlpandashref

How to create a report with hyperlinks that open relative files in Python?


I would like to generate a report with reference links to local files using relative paths. I want this to run on my *nix system and the Windows machines used by others. I have tried the following:

from pandas import *
df = DataFrame(['<a href="http://example.com">example.com</a>'])
df.to_html('file.html')

For some reason this does not render the href for me. I have tried it in multiple browsers and none render the html.

How can I generate a report using python which includes hyperlinks to open files using local paths? I would like this document to be able to be used by others without running python.


Solution

  • You just need to escape the tags.

    df.to_html(pth,escape=False)