本文整理汇总了Python中cherrypy.lib.static.serve_file方法的典型用法代码示例。如果您正苦于以下问题:Python static.serve_file方法的具体用法?Python static.serve_file怎么用?Python static.serve_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cherrypy.lib.static
的用法示例。
在下文中一共展示了static.serve_file方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download
# 需要导入模块: from cherrypy.lib import static [as 别名]
# 或者: from cherrypy.lib.static import serve_file [as 别名]
def download(self, **args):
args = self.clean_args(args)
filepath = self.getDownload(args)
if type(filepath).__name__ == "str":
return serve_file(filepath, "application/x-download", "attachment", name='data.csv')
if type(filepath).__name__ == "instance":
file_obj = serve_fileobj(
filepath.getvalue(),
"application/x-download",
"attachment",
name='data.csv'
)
return file_obj
if type(filepath).__name__ == "StringIO":
file_obj = serve_fileobj(
filepath.getvalue().encode('utf-8'),
"application/x-download",
"attachment",
name='data.csv'
)
return file_obj
else:
return "error downloading file. filepath must be string of buffer"
示例2: download
# 需要导入模块: from cherrypy.lib import static [as 别名]
# 或者: from cherrypy.lib.static import serve_file [as 别名]
def download(self):
path = os.path.join(absDir, 'pdf_file.pdf')
return static.serve_file(path, 'application/x-download',
'attachment', os.path.basename(path))
示例3: error_page_404
# 需要导入模块: from cherrypy.lib import static [as 别名]
# 或者: from cherrypy.lib.static import serve_file [as 别名]
def error_page_404(status, message, traceback, version):
path = os.path.join(curdir, 'static', '404.html')
return static.serve_file(path, content_type='text/html')
示例4: show_img
# 需要导入模块: from cherrypy.lib import static [as 别名]
# 或者: from cherrypy.lib.static import serve_file [as 别名]
def show_img(self, name, mimetype):
fp = path.join(self.datapath, name)
if(path.exists(fp)):
return serve_file(fp, mimetype, name)
else:
tmpl = self.lookup.get_template("404.mako")
cherrypy.response.status = 404
return tmpl.render(page_title="File not found!")
示例5: download
# 需要导入模块: from cherrypy.lib import static [as 别名]
# 或者: from cherrypy.lib.static import serve_file [as 别名]
def download(self, name):
fp = path.join(self.datapath, name)
if(path.exists(fp)):
return serve_file(fp, "application/x-download", "attachment")
else:
tmpl = self.lookup.get_template("404.mako")
cherrypy.response.status = 404
return tmpl.render(page_title="File not found!")
示例6: rss
# 需要导入模块: from cherrypy.lib import static [as 别名]
# 或者: from cherrypy.lib.static import serve_file [as 别名]
def rss(self):
# Return static file with ATOM feed
return serve_file("/bots/telegram-feedgen-bot/static/atom.xml")
示例7: GET
# 需要导入模块: from cherrypy.lib import static [as 别名]
# 或者: from cherrypy.lib.static import serve_file [as 别名]
def GET(self, id=None):
"""Write our image to a temp file, then give it back to the user"""
cv2.imwrite(self.image_file, self.image_callback())
return serve_file(self.image_file, content_type='image/jpeg')
示例8: download
# 需要导入模块: from cherrypy.lib import static [as 别名]
# 或者: from cherrypy.lib.static import serve_file [as 别名]
def download(self):
path = os.path.join(absDir, "pdf_file.pdf")
return static.serve_file(path, "application/x-download",
"attachment", os.path.basename(path))