diff options
Diffstat (limited to 'django')
| -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 |
