diff options
| author | mriduldhall <mriduldhall1@gmail.com> | 2025-07-25 16:27:20 +0100 |
|---|---|---|
| committer | nessita <124304+nessita@users.noreply.github.com> | 2025-07-28 16:41:06 -0300 |
| commit | d4dd3e503c88db92f254769a64b2fcd4c572c7dc (patch) | |
| tree | c2808b0a4c7692a90adf6cd30a9356d31f55409d /django/template | |
| parent | 2d4ca621700eed97f0cb8a19d02a05fc088b26d2 (diff) | |
Fixed #36519 -- Made center template filter consistent for even/odd padding.
Refactored `center` template filter to match f-string behaviour,
producing consistent padding for both odd and even fillings.
Thanks Lily Acorn for the report and Natalia Bidart for the review.
Co-authored-by: Lily Acorn <code@lilyf.org>
Diffstat (limited to 'django/template')
| -rw-r--r-- | django/template/defaultfilters.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index b50b790fc1..3ed9856c08 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -432,7 +432,10 @@ def rjust(value, arg): @stringfilter def center(value, arg): """Center the value in a field of a given width.""" - return value.center(int(arg)) + width = int(arg) + if width <= 0: + return value + return f"{value:^{width}}" @register.filter |
