2010-02-21 61 views
3

我正在嘗試使用Python做一個簡單的echo應用程序。我想用POST表單提交一個文件並將其回顯(HTML文件)。將HTML文件上傳到Google App Engine - 獲得405

這裏是YAML的handlers部分我使用:

handlers: 
- url: /statics 
    static_dir: statics 

- url: .* 
    script: main.py 

它基本上是在main.py hello world示例,我加一個目錄來我的靜態html格式文件。下面是statics/test.html的HTML:

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

處理程序是這樣的:

#!/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() 

但是,發佈文件時,我得到一個錯誤405。怎麼來的?

回答

9

您要提交與POST方法的形式,但可以實現的get()處理程序,而不是post()處理程序。將def get(self):更改爲def post(self):應修復HTTP 405錯誤。

+0

這是一個模型答案。 – 2010-02-22 02:26:18

+0

[facepalm] 爲我在晚上嘗試新SDK提供了正確的方法。謝謝。 – 2010-02-22 06:13:21

相關問題