【发布时间】:2016-12-20 13:34:08
【问题描述】:
我只是在玩python脚本(test.py)有一个函数test1()。
def test1():
return '<button (code ... for one simple button) .... ></button>'
在我的 init.py:
from flask import Flask
from flask import render_template, url_for
import test
abc = test.test1()
app = Flask(__name__)
@app.route("/")
def index():
try:
return render_template('index.html', something=abc)
except Exception as e:
return str(e)
if __name__ == '__main__':
app.run()
在我的 index.html 中有:
<body>
{{something}}
</body>
为什么 html 不将此变量视为代码?如果我直接将<button (code ... for one simple button) .... ></button> 复制到 index.html 并调用 reneder_template(index.html),一切都很好,但是如果我从 test.py html 中调用此字符串,则这是正文标签中的纯文本...解决这个问题的方法?会很感激。基本上,我希望 html 将此字符串作为代码而不是文本来读取。
【问题讨论】:
-
是的,谢谢丹尼尔