我试图使用render_模板返回字符串,但它只返回else语句。但当我试图在控制台中打印时,它就起作用了。但当我想在金贾使用的时候就不行了
def healthchecker():
# health = ""
for key,value in raw.items():
if 'properties' in value:
health = "Yes"
print(health)
else:
health = "None"
print(health)
return health
return render_template('portlist.html', data = raw, health = healthchecker())
您可以只传递字典,而不是将函数传递给模板。然后,您可以轻松地使用它,并在html文件中使用jinja进行迭代
另外,对于PEP 8,在分配关键字参数时,避免在等号周围使用空格
相关问题 更多 >
编程相关推荐