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

4
  • 6
    Console has monospaced font, but your page does not. Commented Mar 21, 2019 at 0:30
  • 2
    You can wrap it between <pre> and </pre> tags but it is better to spit out proper HTML instead and use a <table> for tabular data. Commented Mar 21, 2019 at 0:41
  • Browser will merge multiple consecutive blank spaces, you have to use <pre> tag as @Selcuk said or use css for doing so, see: stackoverflow.com/questions/8994516/… Commented Mar 21, 2019 at 0:52
  • @Selcuk yup, <pre> tags solved this, thanks! Commented Mar 21, 2019 at 11:34

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.