将变量从python(烧瓶)传递到渲染模板中的HTML? [英] Pass Variable from python (flask) to HTML in render template?

查看:48
本文介绍了将变量从python(烧瓶)传递到渲染模板中的HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Web服务器可以工作(python烧瓶),但是当我访问网站时,动物的值应该是(狗),它显示了变量名称animal.(代码有更多内容,但这是概念最简单的版本.

The web server works (python flask) but when I go to the website, where the value of animal should be (dog) it shows the variable name animal. (There is more to the code but this is the most simplistic version which is the same concept.

假设我在运行python flask的python脚本中有这些代码行.

Let's say I have these lines of code in my python script running python flask.

animal = dog
return render_template('index.html', value=animal)

和我的HTML

<h3>I like the animal: {{ value }}<h3>

但不显示"dog",而是显示变量名称"animal".那么如何将Python变量显示为HTML?谢谢

but rather than displaying 'dog' it displays the variable name 'animal'. So how would I go about displaying the Python variable to HTML? Thank you

推荐答案

不是 animal ='dog'吗?如果"dog"是您要在我喜欢动物:"之后看到的值,则需要执行以下操作:

Shouldn't it be animal = 'dog'? If 'dog' is the value you want to see printed after "I like the animal:", this is what you need to do:

animal = 'dog'
return render_template('index.html', value=animal)

这篇关于将变量从python(烧瓶)传递到渲染模板中的HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆