Right justifies a value by padding it with whitespace on the left.
Variable
company = 'Webucator'
Template
{{ "company|rjust:20" }}
Result
" Webucator"
In a browser, whitespace is condensed, so the output would be:
" Webucator"
Argument: n
(required)
– The width of the field in number of characters, in which to justify the value.
Right justifies a value by padding it with whitespace on the left.
company = 'Webucator'
{{ "company|rjust:20" }}
" Webucator"
In a browser, whitespace is condensed, so the output would be:
" Webucator"
Did we get something wrong? Is there a use case for the
rjust
filter that we should add?
Please let us know.
Commentary
As whitespace is condensed by default in HTML pages, alignment filters will not affect the output unless the text is within a
pre
element or CSS is used to prevent whitespace from being condensed. However, Django can be used to create non-HTML documents as well. In such documents, formatting with whitespace might make more sense.