[英]Generate random letters using Jinja for cookiecutter template
I am looking to generate a random 8 letter hash for a cookeicutter template.我正在寻找为 Cookeicutter 模板生成一个随机的 8 个字母的哈希。 In pure Python, this would generate what I'd like:
在纯 Python 中,这将生成我想要的:
In [3]: import random
In [3]: import string
In [4]: ''.join(random.choice(string.ascii_lowercase) for i in range(8))
Out[4]: 'jrqcwtav'
In Jinja, the closest thing I could find would be a multiline solution.在 Jinja 中,我能找到的最接近的东西是多行解决方案。 I need a one-liner.
我需要一个单线。 Any ideas?
有任何想法吗?
If you're using cookiecutter>=1.7
, you can use filter random_ascii_string
like this :如果您使用的是
cookiecutter>=1.7
,则可以像这样使用过滤器random_ascii_string
:
{{ random_ascii_string(8) }}
More information available about random_ascii_string .有关random_ascii_string 的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.