I’m trying to nicely format some text data from database to send in emails in Django. I’m encountering some problems with strings with line breaks.
In particular,my desired output is:
1) t1 t2
t1_continue t2_end
t1_end
2) s1 s3
s1_continue
s1_end
Here the strings taken from database are “t1\nt1_continue\nt1_end”, “t2\nt2_end”, “s1\ns1_continue\ns1_end” and “s3”.
This desired output is like what we see if we’re having 3 columns in Excel.
What I want to say is that some strings contain line breaks so simple formatting such as:
print str(index) + '\t' + col1 + '\t' + col2
won’t work.
Please share with me your approach.
Many thanks.
You can use a
<table>to display tabular data in the email body.Before the loop that
prints each table row,printthe table header:For each data row, format it like so:
Finally, after the loop that
prints each table row,printthe table footer: