Addtional Rows Showing In Doc Table Using Jinja
I have written a jinja code where I want to add the environment and its servers to the table. Desired output: Here is my Jinja code in word: My python code where servers in conte
Solution 1:
What is actually happening here is that the rows are being drawn as empty if your row is string
condition equals false. In order to avoid that you could change strategy altogether. I am assuuming that every server is going to have its "environment" label, and if that is the case, firstly, change the format of your word document to:
Then, adjust your context
structure as follows:
context = {
'headers' : ['Component', 'Component Version', 'Server FQDN', 'Application port', 'DB SID', 'DB Port', 'Infos'],
'servers': []
}
server_1 = {}
server_1['environment'] = 'Qualif'
server_1['cols'] = ["Tomcat",7,'a',5000," ",200,""]
server_2 = {}
server_2['environment'] = 'Dev'
server_2['cols'] = ["Tomcat",7,'b',5000," ",200,""]
context['servers'].append(server_1)
context['servers'].append(server_2)
This way, the produced output will be:
If instead you would like to have multiple servers into one environment
, then you should adjust the context to make it have a similar structure:
context = {
'headers' : ['Component', 'Component Version', 'Server FQDN', 'Application port', 'DB SID', 'DB Port', 'Infos'],
'servers':
{
"Qualif": [],
"Dev" : []
}
}
server_1 = ["Tomcat",7,'a',5000," ",200,""]
server_2 = ["Tomcat",7,'b',5000," ",200,""]
context['servers']['Qualif'].append(server_1)
context['servers']['Qualif'].append(server_2)
context['servers']['Dev'].append(server_1)
context['servers']['Dev'].append(server_2)
And your word file as follows:
And this is eventually what you will get:
Post a Comment for "Addtional Rows Showing In Doc Table Using Jinja"