Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate random number with jinja2

I need to generate a random number between 1 and 50. Aparently the random filter needs a sequence. How can I create a list with numbers from 1 to 50 in Jinja?

{{ [1,n,50]|random() }}
like image 900
user2990084 Avatar asked Apr 18 '16 01:04

user2990084


1 Answers

Jinja2 also includes the range function which returns a sequence of numbers from start to end - 1, so you can use it with random:

Your lucky number is: {{ range(1, 51) | random }}
like image 144
Sean Vieira Avatar answered Nov 05 '22 04:11

Sean Vieira