import tornado.ioloop
import tornado.web
from tornado.options import define,options,parse_command_line
from 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()
原文地址:http://linuxnewstar.blog.51cto.com/6967359/1881071