0

I have

  fruits = [ "apple" , "pineapple" , "banana", "oranges"] 
  sizes = ["small", "medium", "large"]

I want to create a HTML home page.

for this I am currently doing this:

import os

def home_html(func)
    htmlFile = open('home_fruits.html', 'w')
    message = """<DOCType html>
             <html>
             <head>
             <title> Classification of fruits </title>
             </head> 
             <body> <h1> Fruits-Home Page </h1>
             <style type = "text/css">
             style code for the table 
             </style> 
             <table class = "tg">
             <tr>
             <th class="tg-031e">apple</th>
             <th class="tg-031e">banana</th>
             <th class="tg-031e">pineapple</th>
             <th class="tg-031e">oranges</th> 
             </tr> 
             <tr> 
             <td class="tg-031e"><a href = "apple_details.html"</th> Details for apple </a></td>
              similarly for pineapple 
              similarly for banana 
              similarly for oranges 
             </tr> 
             </table>
             </body>
             </html>"""

   htmlFile.write(message)
   htmlFile.close() 

Similarly I create each individual HTML pages like apple_details.html etc. All hardcoding.

Is there some easy way to do this? like instead of

<th class="tg-031e">apple</th>
<td class="tg-031e"><a href = "apple_details.html"</th>

if I do

<th class="tg-031e">fruit</th>

<td class="tg-031e"><a href = "fruit_details.html"</th>

should create automatic table for all the fruits?

The question is not duplicate, it is not asking for template generation. I want to reduce hardcoding.

geek_xed
  • 165
  • 1
  • 8
  • 15
  • I am not looking to generate HTML template in python. I am looking for a way to avoid lengthy hard-coding with fruit names. Instead if I use fruit word, it should generated the table with fruit names. – geek_xed Jul 03 '15 at 18:17
  • 2
    I've never done this in Python but I imagine some of the libraries pointed to in those answers will make it easy to create a table template that excepts data in a certain format so the tables can be populated programmatically. – wwii Jul 03 '15 at 18:23

0 Answers0