1
def method_create_template(data):
    for t in data:
        name=t['name']
        age=t['age']
        with open("directory/file.html",'r') as files:
            files = Template(files.read())
            files=files.render(data1=name,data2=age)
            myTeamsMessage = pymsteams.connectorcard(url)
            myTeamsMessage.title("title")
            myTeamsMessage.text(files)
            myTeamsMessage.color("FF0000")
            response = myTeamsMessage.send()
            print("message sent")

This is my block of code and here the message is sending properly but the requirement is to send one template, I know that i am inside for loop and it will send in loop only but how to send single message which will have my all loop data

this is my for loop data

[{'name': 'putta', 'age': '25'}, {'name': 'xyz', 'age': '80'}}]

my template is

<table ><tr><th>name</th><th>age</th></tr><td>{{data1}}</td><td><a href="{{data2}}"></a>{{data2}}</td></table>

output i am getting is like list is coming

 <table ><tr><th>name</th><th>age</th></tr><td>putta</td><td>25</td></table>
<table ><tr><th>name</th><th>age</th></tr><td>xyz</td><td>80</td></table>....

if i go out loop one data is coming

 name  age
 putta  25

the expected output is .......

name     age
putta     25
xyz       80
abc       90

Thanks for inputs.

putta
  • 35
  • 8
  • Please have a look at related answers [here](https://stackoverflow.com/a/74584131/17865804), [here](https://stackoverflow.com/a/71121812/17865804), as well as [here](https://stackoverflow.com/a/74588435/17865804) and [here](https://stackoverflow.com/a/70996841/17865804). – Chris Dec 21 '22 at 11:35

1 Answers1

0
{
  "data": [{
        "name": "putta",
        "age": "25"
    }]
}

i changed data to like this and added loop in my jinja2 template only and it working !... thanks for others efforts here

<tr><th>Name</th><th>age</th></tr>
    {% for datas in t_data['data'] %} 
           <tr><td>{{data.name}}</td><td>{{data.age}}</a></td></tr>
    {% endfor %}
</table>
putta
  • 35
  • 8