使用html模板处理代码以显示整理数据,但是我所看到的只是HTML中是否存在对象。
这是代码。
def exfoconfigdisplay():
resp = ""
resp += '\nApplying EXFO Configuration...\n\n'
#yield resp
for eLine in varDict['DUT']['A']['EXFO_Config'].splitlines():
resp += "%-10s %s"%('Sending ->', eLine) + '\n'
cResponse = sendToExfoWeb (exHandle,eLine, timeout=3)
resp += 'Received <-- ' + str(cResponse[1]) + '\n'
sleep(1)
yield resp
exHandle.close()
return Response(stream_template('display_something.html',output=(stream_with_context(exfoconfigdisplay()))))
这是我的display_something.html模板。
{% extends "layout.html" %}
{% block content %}
{{ output | safe}}
<br>
<a href="/main"><u>Return to main menu</u></a><br>
<A HREF="javascript:javascript:history.go(-1)"><u>Back</u></A>
<br>
{% endblock %}
我只看到此输出显示在html中。
<generator object generator at 0x10636caf0>
如果我添加mimetype ='text / event-stream'或mimetype ='text / plain',我只会看到带有生成器对象字符串的html标记代码。
<!DOCTYPE html>
<html>
<head>
<title>EXFO Test Config Generator and Tester</title>
<link href="/static/css/main.css" rel="stylesheet">
</head>
<body>
<header>
<h1 class="title">EXFO Config generator and Tester</h1>
</header>
<generator object generator at 0x10636caf0>
<br>
<a href="/main"><u>Return to main menu</u></a><br>
<A HREF="javascript:javascript:history.go(-1)"><u>Back</u></A>
<br>
</body>
</html>
有什么想法可能会出错吗?