本文整理匯總了Python中werkzeug.Response.mimetype方法的典型用法代碼示例。如果您正苦於以下問題:Python Response.mimetype方法的具體用法?Python Response.mimetype怎麽用?Python Response.mimetype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類werkzeug.Response
的用法示例。
在下文中一共展示了Response.mimetype方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: static
# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import mimetype [as 別名]
def static(self, request, filename):
response = Response(open(path.join(web_media_path, filename)).read())
if filename.endswith('.js'):
response.mimetype = 'application/javascript'
elif filename.endswith('.css'):
response.mimetype = 'text/css'
return response
示例2: session_debug
# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import mimetype [as 別名]
def session_debug():
if local.application.debug == False:
return notfound()
from pprint import pformat
local.session.init()
response = Response(pformat(local.session.data))
response.mimetype="text/plain"
response.charset = "utf-8"
return response
示例3: read_pagefile
# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import mimetype [as 別名]
def read_pagefile(url):
wiki = get_wiki()
user = current_user.get_id()
page_url = os.path.dirname(url_from_viewarg(url)).\
replace('\\', '/').\
rstrip('/')
page = get_page_or_raise(wiki, page_url, fields=['path'],
check_perms=(user, 'read'))
# If no exception was thrown, we're good for reading the file.
path_no_ext, _ = os.path.splitext(page.path)
file_path = os.path.join(path_no_ext, os.path.basename(url))
try:
f = open(file_path, 'rb')
except OSError:
abort(404)
r = Response(wrap_file(request.environ, f), direct_passthrough=True)
_, ext = os.path.splitext(url)
r.mimetype = mimetype_map.get(ext, '')
return r
示例4: show_image
# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import mimetype [as 別名]
def show_image(id):
response = Response(user.get_image(id))
response.mimetype="image/jpeg"
return response