Ass*_*vie 3 python google-app-engine
我正在尝试使用Python做一个简单的echo应用程序.我想提交一个带有POST表单的文件并将其回送(HTML文件).
这是handlers
我正在使用的YAML部分:
handlers:
- url: /statics
static_dir: statics
- url: .*
script: main.py
Run Code Online (Sandbox Code Playgroud)
它基本上是hello world示例main.py
,我添加了一个目录来托管我的静态html表单文件.这是HTML中的statics/test.html
:
<form action="/" enctype="multipart/form-data" method="post">
<input type="file" name="bookmarks_file">
<input type="submit" value="Upload">
</form>
Run Code Online (Sandbox Code Playgroud)
处理程序如下所示:
#!/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()
Run Code Online (Sandbox Code Playgroud)
但是,我在发布文件时收到错误405.怎么会?
您使用POST方法提交表单,但是您实现了get()
处理程序而不是post()
处理程序.更改def get(self):
为def post(self):
应该修复HTTP 405错误.
归档时间: |
|
查看次数: |
1000 次 |
最近记录: |