3

enter image description here

row1 = ["Date: "  + date,  "Price:"     + price]
row2 = ["Name: "  + name,  "Quantity: " + quantity]
row3 = ["Title: " + title, "Owned: "    + owned]
row4 = ["Type: "  + type,  "Value: "    + value]

output_text = output_text + "\n" + \
              ('{:30s} {:20s}'.format(row1[0], row1[1])) + "\n" + \
              ('{:30s} {:20s}'.format(row2[0], row2[1])) + "\n" + \
              ('{:30s} {:20s}'.format(row3[0], row3[1])) + "\n" + \
              ('{:30s} {:20s}'.format(row4[0], row4[1])) + "\n"

print(output_text)  

So, printing it to the console shows that the formatting is good, but when seeing it on the localhost website, the formatting seems to have no effect.
What's the best way to align two columns of text and have it stick on the Flask page?

Thanks

Anon Li
  • 561
  • 1
  • 6
  • 18
  • 6
    Console has monospaced font, but your page does not. – minterm Mar 21 '19 at 00:30
  • 2
    You can wrap it between `
    ` and `
    ` tags but it is better to spit out proper HTML instead and use a `` for tabular data.
    – Selcuk Mar 21 '19 at 00:41
  • Browser will merge multiple consecutive blank spaces, you have to use `
    ` tag as @Selcuk said or use css for doing so, see: https://stackoverflow.com/questions/8994516/html-css-best-practice-for-preserving-white-space-on-certain-elements
    – geckos Mar 21 '19 at 00:52
  • @Selcuk yup,
     tags solved this, thanks!
    – Anon Li Mar 21 '19 at 11:34

1 Answers1

2

<pre> </pre> tags solved this formatting issue.

Blastfurnace
  • 18,411
  • 56
  • 55
  • 70
Anon Li
  • 561
  • 1
  • 6
  • 18