[英]how to display python console output on html page using flask
def execute():
print("this is imam")
#perform some task after first print then print next function
print('this akarsh')
#perform some task after first print then print next function
print('this is abhi')
@app.route('/')
def home ():
return render_template('index.html', x= execute())
我只是想在我的 html 页面上打印上面三个打印语句,我尝试使用 set 变量传递,请帮助我。 当它在 python 控制台上打印时,一个接一个地执行上述某些任务。
def execute():
return """
this is imam
this akarsh
this is abhi
"""
如果您使用index.html
作为模板。 它应该如下所示:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h3>This is a parameter from app</h3>
{{ x }}
</body>
</html>
并且您必须像这样更改您的execute()
function:
def execute():
x = 'this is imam'
print("this is imam")
#perform some task after first print then print next function
y = 'this akarsh'
print('this akarsh')
#perform some task after first print then print next function
z = 'this is abhi'
print('this is abhi')
result = [x,y,x]
return result
您可以使用列表(或任何 python 数据结构)来返回结果。
你可以使用这个方法
Outposts
class class Outpost: def __init__(self): self.outposts = [] def add_outpost(self, data): self.outposts.append(data)
execute()
function 复制 Outposts 并运行execute()
: execute_outposts = Outpost() execute()
execute_outposts.add_outpost(text)
替换打印execute_outposts.outposts
放入x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.