我正在尝试将单元测试转换为 py 测试。我正在使用单元测试示例
class TestCase(unittest.TestCase):
def setUp(self):
app.config['TESTING'] = True
app.config['CSRF_ENABLED'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir,
'test.db')
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
Run Code Online (Sandbox Code Playgroud)
我不确定,它的 py 测试版本应该是什么。
我正在编写基于 jinja2 模板的应用程序。我正在尝试编写一个逻辑来设置变量。
{% set last_item = none %}
{% for u in users %}
{% if not u.username == user.username%}
{% if g.user.is_bestfriend(u) %}
{% set last_item = 'true' %}
{% endif %}
{% endif %}
{% endfor %}
{{last_item}}
Run Code Online (Sandbox Code Playgroud)
但之后{% endfor %},last_item值再次设置为 none,而不是 true。有什么方法可以在 jinja2 模板中将其设置为 true 吗?