Generate random number with jinja2

后端 未结 1 1108
北恋
北恋 2020-12-18 19:27

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条回答
  • 2020-12-18 19:58

    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 }}
    
    0 讨论(0)
提交回复
热议问题