1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Fixed #34518 -- Fixed crash of random() template filter with an empty list.

This commit is contained in:
David Sanders
2023-04-26 22:17:57 +10:00
committed by GitHub
parent 18a7f2c711
commit 7d0e566208
2 changed files with 9 additions and 1 deletions

View File

@@ -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)