【发布时间】:2019-08-29 22:01:56
【问题描述】:
对于 web2py,有通用视图,例如对于 JSON。
我找不到样品。
查看 web2py 手册 10.1.2 和 10.1.6 时,它写道: '.. 定义一个“generic.csv”文件,但必须指定要序列化的对象的名称(示例中为“animals”)'
查看通用 pdf 视图
{{
import os
from gluon.contrib.generics import pdf_from_html
filename = '%s/%s.html' % (request.controller,request.function)
if os.path.exists(os.path.join(request.folder,'views',filename)):
html=response.render(filename)
else:
html=BODY(BEAUTIFY(response._vars))
pass
=pdf_from_html(html)
}}
还有指定的 csv(手册章节 10.1.6):
{{
import cStringIO
stream=cStringIO.StringIO() animals.export_to_csv_file(stream)
response.headers['Content-Type']='application/vnd.ms-excel'
response.write(stream.getvalue(), escape=False)
}}
Massimo 正在写:'web2py 不提供“generic.csv”;'
他并不完全反对,但是..
因此,让我们尝试获取它并在必要时停用它。 通用视图应类似于(非工作) (好吧,我们最好将其称为伪代码,因为它不起作用):
{{
import os
from gluon.contrib.generics export export_to_csv_file(stream)
filename = '%s/%s' % (request.controller,request.function)
if os.path.exists(os.path.join(request.folder,'views',filename)):
csv=response.render(filename)
else:
csv=BODY(BEAUTIFY(response._vars))
pass
= export_to_csv_file(stream)
}}
怎么了? 或者有样品吗? 没有通用的 csv 是否有道理?
【问题讨论】: