python - 使用您刚刚在烧瓶上运行的函数的数据渲染模板
问题描述
当我尝试使用函数结果渲染烧瓶模板时,它显示“未定义 y 值”
我的功能:
functiona (x):
y=x+1
return y
我的烧瓶:
@app.route('/example')
def example():
functiona (1)
return render_template(template.html, y=y)
解决方案
将函数的结果赋给一个变量。然后你就可以稍后使用它,例如在下一行
@app.route('/example')
def example():
y = functiona (1)
return render_template(template.html, y=y)
推荐阅读
- mysql - 选择具有关系的多对多数据并在结果中添加新列
- android - 应用程序:compileDebugJavaWithJavac'。> 找不到 tools.jar 无法启动模拟器。原因:没有找到模拟器作为 `emulator -list-avds` 的输出
- html - 将图片链接作为道具传递
- laravel - Laravel 8 向 CopyAndPay Api 发出 POST 请求并呈现表单
- ios - AKOscillator 频率范围用于 iOS 中的Theremin 声音
- .net - SERVERPROPERTY 中的 EngineEdition "SQL Database" 是什么 SQL Server 版本或平台
- javascript - 作为 html 脚本的一部分更改文本属性
- android - Android studio 无法识别旧版本的 gradle 文件
- flutter - 执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade 时发生故障 Flutter clean 后
- ruby-on-rails - Rails 中的验证