import tornado.ioloopimport tornado.webfrom tornado.options import define,options,parse_command_linefrom tornado.web import RequestHandler class PicHandles(RequestHandler): def get(self): data={} data[‘pic_id‘]=self.request.uri.split(‘/‘)[-1:][0] if int(data[‘pic_id‘])==1: pic=open(‘/home/wang/Desktop/canpin/1.jpg‘,‘r‘) pics=pic.read() # result=base64.encodestring(pics) self.write(pics) self.set_header("Content-type", "image/png") else: self.write("no url") define(‘port‘,default=8000,type=int,)def main(): parse_command_line() app=tornado.web.Application( [ (r"/pic/*.*",PicHandles),], debug=True, default_host="0.0.0.0",) app.listen(options.port) tornado.ioloop.IOLoop.instance().start() if __name__==‘__main__‘: main()
时间: 2024-10-27 13:22:58