AidenEllis / HTMLTemplateRender

A html template renderer that renders the html file with variables.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTMLTemplateRender

  • Rendering html file with variables into text

Installation

  • Install Package Using pip
    python3 pip install HTMLTemplateRender

How to use:

  • HTML File (test.html) Use {{ variable }} to assign value

     <!DOCTYPE html>
     <html lang="en">
     <head>
         <meta charset="UTF-8">
         <title>Test</title>
     </head>
     <body>
         <h1>Hey there {{ username }}</h1>
         <h2>It's {{ day_name }}</h2>
     </body>
     </html>
    • Lets Render the file
    from HTMLTemplateRender.renderer import render_template
    
    context = {
        'username': 'Anonymous',
        'day_name': 'Sunday'
    }
    
    result = render_template(template_path='test.html', context=context)
    print(result)
  • Output

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Test</title>
    </head>
    <body>
        <h1>Hey there Anonymous</h1>
        <h2>It's Sunday</h2>
    </body>
    </html>
    
    Process finished with exit code 0

About

A html template renderer that renders the html file with variables.

License:MIT License


Languages

Language:Python 92.2%Language:HTML 7.8%