首页 > 解决方案 > 使用您刚刚在烧瓶上运行的函数的数据渲染模板

问题描述

当我尝试使用函数结果渲染烧瓶模板时,它显示“未定义 y 值”

我的功能:

functiona (x):
    y=x+1
    return y

我的烧瓶:

@app.route('/example')
def example():
    functiona (1)
    return render_template(template.html, y=y)

标签: pythonhtmlflask

解决方案


将函数的结果赋给一个变量。然后你就可以稍后使用它,例如在下一行

@app.route('/example')
def example():
    y = functiona (1)
    return render_template(template.html, y=y)

推荐阅读