作者gn00618777 (非常念旧)
看板Python
标题[问题] 在客户端的网页显示
时间Sat Jan 17 10:12:17 2015
我一个 html档,运行在 host,他的内容只有 <h1>{{ result }}</h1>,是要给
客户端看得显示页面。
我web主程式,里面一个function是执行某个指令:
@app.route("/test",methods=['GET','POST'])
def function test():
import subprocess
cmd=subprocess.Popen(['ifconfig','eth0'],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out,err=cmd.communicate()
templateData={
'result' : out
}
return render_template('xxx.html',**templateData)
他在客户端显示的讯息都是连在一起没有分段,如果我在web主程式打print(out)
他在这边就像linux显示那样整齐,有甚麽比较聪明的办法可以让他像显示在 linux
那样地显示在客户端? 有python提供的API吗? 谢谢。
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 220.136.153.30
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1421460743.A.863.html
※ 编辑: gn00618777 (220.136.153.30), 01/17/2015 10:13:05
2F:→ gn00618777: 哈哈哈哈 这到底在说啥阿 QQ 01/17 13:07
3F:→ gn00618777: 看起来就是用 nl2br 这函式将 output 换行 01/17 13:12
4F:→ gn00618777: 他会对印出的\n做出换行的html tag 01/17 13:20
5F:→ gn00618777: nl2br function 我需要额外创吗...? 谢谢 01/17 13:23
6F:→ gn00618777: 我想到用js来解决.. 01/17 17:12