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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user