summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorDavid Sanders <shang.xiao.sanders@gmail.com>2023-04-26 22:17:57 +1000
committerGitHub <noreply@github.com>2023-04-26 14:17:57 +0200
commit7d0e56620882c207998a41ac07ec5da572045b31 (patch)
tree690f4d6e68dcc4fa057a6225cf214f9b17be6447 /django
parent18a7f2c711529f8e43c36190a5e2479f13899749 (diff)
downloaddjango-7d0e56620882c207998a41ac07ec5da572045b31.tar.gz
Fixed #34518 -- Fixed crash of random() template filter with an empty list.
Diffstat (limited to 'django')
-rw-r--r--django/template/defaultfilters.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index d446b54ade..03676533b7 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -628,7 +628,10 @@ def length_is(value, arg):
@register.filter(is_safe=True)
def random(value):
"""Return a random item from the list."""
- return random_module.choice(value)
+ try:
+ return random_module.choice(value)
+ except IndexError:
+ return ""
@register.filter("slice", is_safe=True)