flask中是不是有类似于Django的render_to_string和HttpResponse函数

45 views
Skip to first unread message

wangfeng

unread,
Feb 23, 2012, 4:19:46 AM2/23/12
to python-cn(华蟒用户组,CPyUG 邮件列表)
找了半天也没有发现flask中有这样的函数,只有个 make_response函数但是我现在的工作就是实现

return HttpResponse(content=render_to_string(file_name),
mimetype='text/plain'),求各位帮忙了

wangfeng

unread,
Feb 23, 2012, 4:28:58 AM2/23/12
to python-cn(华蟒用户组,CPyUG 邮件列表)
呵呵 找到了找的不到位Response就可以,但是没有发现render_to_string这样的函数。

闲云无心

unread,
Feb 23, 2012, 4:32:18 AM2/23/12
to pyth...@googlegroups.com


在 2012年2月23日 下午5:28,wangfeng <wangfe...@gmail.com>写道:
呵呵 找到了找的不到位Response就可以,但是没有发现render_to_string这样的函数。

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: pyth...@googlegroups.com
退订: python-cn+...@googlegroups.com (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html



flask的render_template就是django的render_to_string

views里返回字符窜, flask会自动替你make_response一下

Maple

unread,
Feb 24, 2012, 1:55:01 AM2/24/12
to pyth...@googlegroups.com
flask中本身使用的就是类似render_to_string的shortcut方法render_template, 如
   return render_template('index.html', username = username)
然后如果要自己定制response header的内容,可以用make_response函数,你可以参考官方的文档http://flask.pocoo.org/docs/api/#flask.make_response


2012/2/23 闲云无心 <ro...@pearer.com>



--

胡淼
Sun Yat-sen University
The Guangdong Key Laboratory of Information Security Technology(IST)
Blog: http://blog.lovemaple.info/

Reply all
Reply to author
Forward
0 new messages