首页 > 解决方案 > 如果cookiecutter模板中未定义变量,如何设置默认值?

问题描述

我正在使用 cookiecutter 1.7.3

我想要一种方法来设置默认值,以防模板中存在未定义的变量。

我试过的

在 jinja 中使用默认过滤器

"github_username": "{{ cookiecutter.github_repo.owner.login|default('Your GitHub username here', true) }}"

或布尔值

"github_username": "{{ cookiecutter.github_repo.owner.login or 'Your GitHub username here' }}"

这些都不起作用。我仍然在模板错误中得到未定义的变量。

可以指教吗?

标签: cookiecutter

解决方案


推荐阅读