本文整理匯總了Python中werkzeug.Response.content_disposition方法的典型用法代碼示例。如果您正苦於以下問題:Python Response.content_disposition方法的具體用法?Python Response.content_disposition怎麽用?Python Response.content_disposition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類werkzeug.Response
的用法示例。
在下文中一共展示了Response.content_disposition方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __call__
# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import content_disposition [as 別名]
def __call__(self, env, start_response):
req = Request(env)
Config = ConfigParser()
Config.read(configfile)
params = {"host": "", "user": "", "database": "", "port": ""}
for param in params:
if not Config.has_option("MySQL", param):
print "Malformed configuration file: mission option %s in section MySQL" % (param)
sys.exit(1)
params[param] = Config.get("MySQL", param)
#print params
#engine = create_engine("mysql+mysqldb://%s:%[email protected]%s:%s/%s?charset=utf8&use_unicode=0" %
# (params["user"], secret.MySQL, params["host"], params["port"], params["database"]), pool_recycle=3600)
Base = declarative_base(bind=engine)
local.Session = []
local.Package = []
local.Session.append(sessionmaker(bind=engine))
local.Package.append(makePackage(Base))
resp = Response(status=200, content_type="text/plain")
if req.path == '/pkg/upload':
resp.content_type="text/html"
resp.response = self.__upload(req)
return resp(env, start_response)
elif req.path == '/pkg/sdk':
resp.content_disposition="application/force-download"
resp.content_type="application/python"
resp.headers.add("Content-Disposition", "attachment; filename=appcfg.py")
f = open("appcfg.py").read().replace("__REPO_UPLOAD__", '"%s"' % (req.host_url + 'pkg/upload'))
resp.headers.add("Content-Length", str(len(f)))
resp.response = [f]
return resp(env, start_response)
elif req.path.startswith('/pkg'):
resp.status_code, resp.content_encoding, resp.response = self.__download(req)
return resp(env, start_response)
else:
resp.status_code = 404
resp.response = [""]
return resp(env, start_response)