Re: [问题] 在客户端的网页显示

楼主: gn00618777 (非常念旧)   2015-01-17 14:00:14
这是我的程式码...
主程式:
from flask import Flask,url_for,send_from_directory,render_template
app=Flask(__name__)
from filter import nl2br
app.jinja_env.filters['nl2br']=nl2br
@app.route("/")
def hello1():
import subprocess
cmd=subprocess.Popen(['ifconfig'],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out=cmd.communicate()
templateData={
'result' : out
}
return render_template('test.html',**templateData)
if __name__=="__main__":
app.run(host='192.168.10.128',port=1300,debug=True)
==============================================================================
filter.py:
#!/usr/bin/env python
import re
from jinja2 import evalcontextfilter, Markup, escape
_paragraph_re = re.compile(r'(?:\r\n|\r|\n){2,}')
@evalcontextfilter
def nl2br(eval_ctx, value):
result = u'\n\n'.join(u'<p>%s</p>' % p.replace('\n', '<br>\n')
for p in _paragraph_re.split(escape(value)))
if eval_ctx.autoescape:
result = Markup(result)
return result
==============================================================================
test.html:
<h1>{{ result | nl2br }}</h1>
显示还是一样....谢谢。
作者: ccwang002 (亮)   2015-01-17 17:34:00
你要不要贴一下你 render 完页面的原始码…http://stackoverflow.com/a/21154829'<br>\n' 改成 Markup('<br/>\n') 看看吧
楼主: gn00618777 (非常念旧)   2015-01-19 11:23:00
cc大,用您的建议,她可以显示出来了,谢谢。

Links booklink

Contact Us: admin [ a t ] ucptt.com