1. 程式人生 > >Tornado 檔案操作筆記

Tornado 檔案操作筆記

import tornado.web
import tornado.ioloop
import tornado.options
import tornado.httpserver
from tornado.options import options
from tornado.web import RequestHandler, url

tornado.options.define('port', type=int, default=8000, help="伺服器埠")

class IndexHandler(RequestHandler):
    def post(self):
        
# print(self.request.files) # 獲取傳遞過來的檔案屬性 # print(self.request.files.keys()) # 可檢視傳遞過來的檔名 # print(self.request.files['image']) # 獲取檔案 print(type(self.request.files['image'])) # 輸出的型別是list self.write('OK!') if __name__ == '__main__': tornado.options.parse_command_line() app
= tornado.web.Application([ (r'/', IndexHandler) ], debug=True) http_server = tornado.httpserver.HTTPServer(app) http_server.listen(options.port) tornado.ioloop.IOLoop.current().start()