0

I have a table in my HTML and I want to put a float variable into a column. I also want this variable to justify itself to the right.

Currently, I am trying {{ float|floatformat:2|rjust }}, but it keeps throwing up a TemplateSyntaxError. Is it even possible to do this via the template system, or will I just have to use some CSS styling for this?

Parker E.
  • 80
  • 7

2 Answers2

4

According to the docs:

"{{ value|rjust:"10" }}"

If value is Django, the output will be "____Django".

EDIT: If you do use this solution, be sure to surround the element with a <pre> tag because extra spaces are removed by your browser. Or look here for info.

Community
  • 1
  • 1
Laurynas Tamulevičius
  • 1,479
  • 1
  • 11
  • 25
0

{{ value|rjust:"10" }} didn't work for me so I had to format the string before being passed to the HTML page.

I first right aligned the string with an arbitrary character:

amount.rjust(12, '$')

And then replace the character with "&nbsp;"

amount.replace('$', '&nbsp;')

Dharman
  • 30,962
  • 25
  • 85
  • 135
flopezlira
  • 71
  • 2
  • 5