从main函数调用ServeHandler

时间:2012-03-28 16:47:19

标签: python google-app-engine blobstore python-2.5

我正在尝试通过URL将参数从python页面传递给另一个,这个参数(我的问题中的键)正确传递但在另一个页面中我有这个代码:

from google.appengine.ext import blobstore
from google.appengine.ext import webapp
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp.util import run_wsgi_app
import urllib
import urllib2        
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
    def get(self):

          blob_key = self.request.get('key')
          blob_key = str(urllib.unquote(blob_key))
          blob_info = blobstore.BlobInfo.get(blob_key)
          self.send_blob(blob_info)

def main():

     application = webapp.WSGIApplication(
    [('/',ServeHandler),], debug=True)
    run_wsgi_app(application)

if __name__ == '__main__':
    main()

但是类ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):没有执行的问题,当我运行此代码时,输​​出是

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

虽然参数传递正确;这是url和key(参数):

http://localhost:8080/download.py?key=vzsX4xM1EtNak5RQVxj4BQ==

编辑: 这是我的app.yaml代码:

application: myapplication
version: 1
runtime: python
api_version: 1

handlers:
- url: /compress.py
  script: compress.py
- url: /download.py
  script: download.py
- url: /decompress.py
  script: decompress.py
- url: (.*)/
  static_files: static\1/index.html
  upload: static/index.html

我想要一个解决这个问题的方法吗?欢迎任何建议。

1 个答案:

答案 0 :(得分:3)

/download.py甚至不在你的app.yamlwebapp如何找到正确的脚本来运行?

现在专注于下载脚本,这是app.yaml应该如何显示的示例:

handlers:
- url: /.*
  script: download.py

编辑:
或者,您可以为下载URL指定更具体的正则表达式模式:

def main():
    application = webapp.WSGIApplication([
            (r'/download.*', ServeHandler),
        ], debug=True)

URL就像:

http://localhost:8080/download?key=vzsX4xM1EtNak5RQVxj4BQ==