title: Insert HTML into python HTML template
body: <pre><code>##### CREATE HTML TEMPLATE ######
  
  html_template = """&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
    &lt;head&gt;
  
      &lt;meta charset = 'UTF-8'&gt;
  
      &lt;title&gt;SHOPPING OUTLET&lt;/title&gt;
  
    &lt;/head&gt;
  
    &lt;body&gt;
  
        $items$
  
    &lt;/body&gt;
  
  &lt;/html&gt;
  """
  
  def print_invoice():
      # Get the document's title
      title = 'invoice'
  
      # Replace elements with items(name, img, price) in the HTML template
  
      html_code = html_template.replace('$items$', '$items$') * count
      html_code = html_code.replace('$items$', '&lt;h1&gt;***TITLE***&lt;/h1&gt; &lt;\b&gt; &lt;p&gt;&lt;img src = ***IMG***&gt;&lt;/p&gt; &lt;\b&gt; &lt;p&gt; Our Price:  ***PRICE***&lt;/p&gt; &lt;\b&gt;')
      for html_replace in range(count):
          html_code = html_code.replace('***TITLE***', html_names[html_replace])
          html_code = html_code.replace('***IMG***', html_imgs[html_replace])
          html_code = html_code.replace('***PRICE***', html_prices[html_replace])
      # Write the HTML code to a Unicode text file
      html_file = open(title + '.html', 'w', encoding = 'UTF-8')
      html_file.write(html_code)
      html_file.close()
  </code></pre>
  
  <p>So to start I have a tkinter interface that acts as a shopping outlet/interface and this HTML is to generate an invoice of items added to a cart. I created three separate lists for the individual elements of the items selected as I feel it's probably easier to format the HTML with separate lists?</p>
  
  <p>This currently adds the last item pressed to all the HTML blocks that were created. I realize the for loop is currently not doing anything as the html_code.replace is adding the last item selected to all the >>>TITLE&lt;&lt;&lt; etc. sections of the HTML template. </p>
  
  <p>Do I run a for loop that creates one massive string and then simple insert it as a whole block or is it better to add each item individually. </p>
  
  <pre><code>for html_replace in range(count):
      html_code = '&lt;h1&gt;' + html_names[html_replace] + '&lt;\h&gt;' etc...
      #Not sure if this will work
  </code></pre>
  
  <p>I had also considered moving the html_code.replace sections into the add_to_cart button press and making the items add individually when the add_to_cart button is pressed. </p>
  
  <p>Am new to coding and just trying to understand the best way to do this. 
  I did find some info on using beautiful soup but am unsure if I can use for this (waiting on response from lecturer).</p>