[英]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())
I just wanted to print the upper three print statements on my html page i have tried with the set variable to pass, please help me with this.
我只是想在我的 html 页面上打印上面三个打印语句,我尝试使用 set 变量传递,请帮助我。 As it prints on python console one after the other performing certain task as mentioned.
当它在 python 控制台上打印时,一个接一个地执行上述某些任务。
def execute():
return """
this is imam
this akarsh
this is abhi
"""
If you are using index.html
as a template.如果您使用
index.html
作为模板。 It should look like this:它应该如下所示:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h3>This is a parameter from app</h3>
{{ x }}
</body>
</html>
and you have to change your execute()
function like this:并且您必须像这样更改您的
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
You can use a list (or any python data structure) to return your results.您可以使用列表(或任何 python 数据结构)来返回结果。
You can use this method你可以使用这个方法
Outposts
classOutposts
class class Outpost: def __init__(self): self.outposts = [] def add_outpost(self, data): self.outposts.append(data)
execute()
function and run execute()
:execute()
function 复制 Outposts 并运行execute()
: execute_outposts = Outpost() execute()
execute_outposts.add_outpost(text)
execute_outposts.add_outpost(text)
替换打印execute_outposts.outposts
in x
execute_outposts.outposts
放入x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.