Unit Converter Web Application Version 3 | Learn Python From Scratch 21 | Kovolff
Channel: prelearn
Date: 2020-11-24

Professional web applications base their user interface on HTML templates. Typically these HTMl templates are linked with a CSS stylesheet.

Templates contain placeholders, typically keywords enclosed in curly braces. Python will then replace these placeholders with dynamically generated content.

Step 1: Have Template
Ensure that you have access to the template file(s)

Step 2: Open Template
In your python code, create a new variable coupled with the Python function open() to open the HTML template in read mode.
i.e.:
page_template = open)”template_main.html, “r”)

The open function demands two parameters: the path to the file to be opened and the mode you wish to open this file in.

Once opened, you assign the content of the file to a variable:
i.e.
html_code = page_template.read()

html_code now contains all the template’s content as string.

Finally all placeholders can be replaced with dynamically generated content using the .format function, discussed in an older video in this series.

#python #html #css