我使用python开发Google应用程序引擎。我创建了zip存档到blobstore,但是当我尝试下载此文件时出现问题。从谷歌应用程序中的blobstore下载zip档案
我将展示一些细节:首先,我在blob上创建了这个存档,然后我得到了这个上传文件的关键。我想在URL发送此项另一个Python页面这样的:
print'<a href="download.py?key=%s">Save Zip</a>' % blob_key
在download.py页
现在,我试图让从网址为重点: self.request.get(“钥匙” ),但它不起作用。
在这个页面中,我写
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
......等
这是我用来下载的zip唯一的类,但问题是我不能拿到钥匙,当我运行应用程序,我得到这个问题:
****Status: 404 Not Found
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 0****
的app.yaml代码:
application: cloudcomputingproject20122012
version: 1
runtime: python
api_version: 1
handlers:
- url: /compress.py
script: compress.py
- url: /decompress.py
script: decompress.py
- url: (.*)/
static_files: static\1/index.html
upload: static/index.html
现在在compress.py我做了两个类;创建zip,将其存储在blobstore上,获取这个存储文件的bob键然后我定义了blob键作为全局变量,现在在服务处理程序类中,我尝试下载此zip,但我不能。
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):
global x
#x="tvsD0KgYxX85hyC9wJHsqw=="
print x
x = str(urllib.unquote(x))
blob_info = blobstore.BlobInfo.get(x)
self.send_blob(blob_info,save_as=True)
def main():
application = webapp.WSGIApplication([('/serve', ServeHandler),], debug=True)
c=zip()
c.z()
run_wsgi_app(application)
if __name__ == "__main__":
main()
你确实真的不想用'print'语句生成HTML输出。只是不要这样做。花一点时间学习Python模板引擎。 Django 1.2引擎包含在AppEngine SDK中。 – 2012-03-19 22:07:28
Jinja也包含在Python 2.7中。 – 2012-03-20 10:57:48