Specify width of fields in Jinja Templates

Viewed 4172

Is there a way to specify the width of each field in Jinja template?

For example I want my output to be displayed like this:

Name           Roll  Address                      Subject1        Subject2  

I want each field to have a width associated with it. Each field has a different width

I have found a way to do this with the help of Python formatting

template = "{:20} {:2} {:30} {:10} {:10}"
fields = template.format("Name", "Roll", "Address","Subject1", "Subject1")
print(fields)

However, I need a way to do this in Jinja2 because I have a ton of fields and some of them require conditional formatting. Is there a way to do this without having to hard-code the spaces in between?

{{Name}}              {{Roll}}  {{Address}}             {{Subject1}}              {{Subject2}} 
1 Answers
Related