ZeroRez
ZeroRez

Reputation: 605

Python mail script and inserting variables into the html code

I tried to use templates and string formatting but nothing seemed to work.

I'm trying to prompt for user input so they can set a time in the html code. Here's a snippit of the code:

my_html = """\
<html>
    <head>
        <title>Something goes here</title>
    </head>
    <body>
        <div style="font-family: 'Segoe UI', Helvetica, Arial, sans-serif;">
            <font face="Calibri,sans-serif" size="2"><span style="font-size: 14px;"><b>When: &nbsp;</b>$the_time_goes_here</span></font></div>

        </div>
    </body>
</html>
"""
the_time_goes_here = raw_input("What's the start time?\n")

I want to get "the_time_goes_here" to populate data in the html code.

Upvotes: 1

Views: 60

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180441

Use str.format using a placeholder {} for the string pass into raw_input :

my_html = """\
<html>
    <head>
        <title>Something goes here</title>
    </head>
    <body>
        <div style="font-family: 'Segoe UI', Helvetica, Arial, sans-serif;">
            <font face="Calibri,sans-serif" size="2"><span style="font-size: 14px;"><b>When: &nbsp;</b>{0}</span></font></div>

        </div>
    </body>
</html>
""".format(raw_input("What's the start time?\n"))

Upvotes: 3

Related Questions