开发者

Uploading a HTML file to Google App Engine - getting 405

I'm trying to do a simple echo app using Python. I want to submit a file with a POST form and echo it back (an HTML file).

Here's the handlers section of the YAML I'm using:

handlers:
- url: /statics
  static_dir: statics

- url: .*
  script: main.py

It's basically the hello world example in main.py and I added a directory to host开发者_开发技巧 my static html form file. Here's the HTML in statics/test.html:

<form action="/" enctype="multipart/form-data" method="post">
    <input type="file" name="bookmarks_file">
    <input type="submit" value="Upload">
</form>

The handler looks like this:

#!/usr/bin/env python
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util

class MainHandler(webapp.RequestHandler):
  def get(self):
    self.response.headers['Content-Type'] = 'text/plain'
    self.response.out.write(self.request.get('bookmarks_file'))

def main():
  application = webapp.WSGIApplication([('/', MainHandler)],
                                       debug=True)
  util.run_wsgi_app(application)

if __name__ == '__main__':
  main()

However, I'm getting an error 405 when posting the file. How come?


You are submitting your form with the POST method, but you implemented a get() handler instead of a post() handler. Changing def get(self): to def post(self): should fix the HTTP 405 error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜