【问题标题】:Why upload handler not match when using GAE blobstore为什么使用 GAE blobstore 时上传处理程序不匹配
【发布时间】:2014-02-07 15:26:04
【问题描述】:

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

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)

[更新1] 单击提交按钮后,我检查了 dev-server Blobstore 查看器,我发现文件已上传到那里,但是,我的 chrome 浏览器仍然显示'The url "/upload" does not match any handlers.'。这是为什么?

【问题讨论】:

  • app.yaml 的处理程序部分有什么?有什么映射/上传到这个 python 模块的吗?
  • @Greg app.yaml 只有一个处理程序。 - url:/脚本:AppWS.application
  • 还有一件奇怪的事情,在开发服务器日志中,没有任何 logging.info('Upload handler') 信息,似乎我的 UploadHandler 没有被调用,但是文件已上传到开发服务器blobstore,上传 URL 始终是 (localhost:8080/_ah/upload/…) 发生了什么?

标签: python google-app-engine blobstore


【解决方案1】:

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

在我改变之后

- 网址:/ 脚本:AppWS.application

- 网址:(/.*)* 脚本:AppWS.application

一切正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-06
    • 2017-06-19
    • 1970-01-01
    • 1970-01-01
    • 2015-06-18
    • 2014-01-06
    • 2012-04-30
    • 1970-01-01
    相关资源
    最近更新 更多