使用GAE blobstore时为什么上传处理程序不匹配

时间:2014-01-18 05:34:30

标签: python google-app-engine blobstore

我只是按照GAE的文档(https://developers.google.com/appengine/docs/python/blobstore/#Python_Uploading_a_blob)编写上传处理程序来上传blobstore,当我在计算机上选择一个文件并点击HTML页面上的提交按钮时,它会显示'The url“/ upload”不匹配任何处理程序。'    任何评论表示赞赏。

class MainPage(webapp2.RequestHandler):
    def get(self):

        self.response.headers['Content-Type'] = 'text/html; charset=utf-8'

        upload_url = blobstore.create_upload_url('/upload')
        logging.info(upload_url)

        self.response.out.write('<html><body>')
        self.response.out.write('<form action="%s" method="POST" enctype="multipart/form-data">' % upload_url)
        self.response.out.write("""Upload File: <input type="file" name="file"><br> <input type="submit"
            name="submit" value="Submit"> </form></body></html>""")

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):

    def post(self):
        logging.info('Upload handler')
        upload_files = self.get_uploads('file')  # 'file' is file upload field in the form
        blob_info = upload_files[0]
        logging.info(upload_files)
        self.redirect('/serve/%s' % blob_info.key())


class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):

    def get(self, resource):
        resource = str(urllib.unquote(resource))
        logging.info(resource)
        blob_info = blobstore.BlobInfo.get(resource)
        self.send_blob(blob_info)


application = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/upload', UploadHandler),
    ('/serve/([^/]+)?', ServeHandler),
], debug=True)

[UPDATE1] 点击提交按钮后,我检查开发服务器Blobstore Viewer,我发现文件已经上传到那里,但是,我的Chrome浏览器仍然显示“网址”/上传“与任何处理程序都不匹配。”。这就是为什么?

1 个答案:

答案 0 :(得分:0)

我想问自己的问题,也许有人遇到与我类似的问题。

更改后
- url: /
  script: AppWS.application

- url: (/.*)*
  script: AppWS.application

一切都很好。