我想在 hooks/pre_gen_project.py 中使用动态变量。
当我在挂钩文件中添加静态文本时,它会起作用:
{{ cookiecutter.update({"venv_path": "static/venvpath", "py_path": "static/pypath"}) }}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用像这样的变量时venv_path_val
venv_path_val = "static/venvpath"
py_path_val = "static/pypath"
{{ cookiecutter.update({"venv_path": venv_path_val, "py_path": py_path_val }) }}
Run Code Online (Sandbox Code Playgroud)
我正进入(状态
jinja2.exceptions.UndefinedError:'venv_path_val'未定义
我也在里面尝试过,eval但没有运气:
eval("{{ '{{'|safe }} cookiecutter.update({'venv_path': venv_path, 'py_path': py_path}) {{ '}}'|safe }}")
Run Code Online (Sandbox Code Playgroud)
那么有没有办法将我的动态模板变量注入 cookiecutter 中?