服务端程序:
import tornado.web import os IMG_LIST=[] class IndexHandler(tornado.web.RequestHandler): def get(self): self.render('index.html',list_img=IMG_LIST) def post(self, *args, **kwargs): name=self.get_argument('name') pwd=self.get_argument('pwd') #fn=self.get_argument('img') file_meta=self.request.files['img'] for meta in file_meta: file_name=meta['filename'] file_path=os.path.join('img',file_name); IMG_LIST.append(file_path) with open(os.path.join('static',file_path),"wb") as fp: fp.write(meta['body']) self.write('{"status":1,"message":"mmm"}') settings ={ 'template_path':'views', 'static_path':'static', 'static_url_path':'sss' } application = tornado.web.Application([ (r"/index",IndexHandler), ],**settings) if __name__=="__main__": application.listen(8080) tornado.ioloop.IOLoop.instance().start()