當前位置: 首頁>>代碼示例>>Python>>正文


Python static.serve_file方法代碼示例

本文整理匯總了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" 
開發者ID:adamhajari,項目名稱:spyre,代碼行數:26,代碼來源:server.py

示例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)) 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:6,代碼來源:tut09_files.py

示例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') 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:5,代碼來源:test_static.py

示例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!") 
開發者ID:SecPi,項目名稱:SecPi,代碼行數:10,代碼來源:alarmdata.py

示例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!") 
開發者ID:SecPi,項目名稱:SecPi,代碼行數:10,代碼來源:alarmdata.py

示例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") 
開發者ID:MasterGroosha,項目名稱:telegram-rss-generation,代碼行數:5,代碼來源:sample_custom_post.py

示例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') 
開發者ID:patrickpoirier51,項目名稱:OpenTracker,代碼行數:6,代碼來源:web_server.py

示例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)) 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:6,代碼來源:tut09_files.py


注:本文中的cherrypy.lib.static.serve_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。