Home > Software design >  How to create html table using python?
How to create html table using python?

Time:07-07

I have been searching to get good html table from python.

Note: I was able to create one and code is given answers section.

CodePudding user response:

I would suggest the easiest implementation would be using streamlit. It is an easy to use python module for creating web apps to present data that handles the HTML/CSS through components. It handles the appearance, you handle the data.

CodePudding user response:

I would say this will probably be the easiest way to create simple html table using python.

html = f"""<table border='1' style="font-family: arial, sans-serif; border-collapse: collapse; width: 100%;">
                <tr>
                    <th style="border: 1px solid #dddddd; text-align: left; padding: 8px;">{header_name_1}</th>
                    <th style="border: 1px solid #dddddd; text-align: left; padding: 8px;">{header_name_2}</th>
                    <th style="border: 1px solid #dddddd; text-align: left; padding: 8px;">{header_name_3}</th>
                    <th style="border: 1px solid #dddddd; text-align: left; padding: 8px;">{header_name_4}</th>
                    <th style="border: 1px solid #dddddd; text-align: left; padding: 8px;">{header_name_5}</th>
                </tr>
            """
for data in datas:
        html  = f"""<tr>
                        <td style="border: 1px solid #dddddd; text-align: left; padding: 8px;">{data_name_1}</td>
                        <td style="border: 1px solid #dddddd; text-align: left; padding: 8px;">{data_name_2}</td>
                        <td style="border: 1px solid #dddddd; text-align: left; padding: 8px;">{data_name_3}</td>
                        <td style="border: 1px solid #dddddd; text-align: left; padding: 8px;">{data_name_4}</td>
                        <td style="border: 1px solid #dddddd; text-align: left; padding: 8px;">{data_name_5}</td>
                    </tr>
                """
    
html = html   "</table>"
  • Related