python怎么处理html中的图片

时间:2014-07-03 06:39:21   收藏:0   阅读:220

在使用的是 Template(open(file)) 引入的 html, 在处理静态文件的时候,怎么处理图片?

可以这样:

def imgFile(environ, start_response):
    ext = environ[‘PATH_INFO‘].split(‘.‘)
    for n in ext:
        mime = n
    m = [(‘content-type‘, ‘image/‘+mime)]  
    start_response(‘200 OK‘, m)  
    
    image = open(os.getcwd()+environ[‘PATH_INFO‘], "rb")
    if ‘wsgi.file_wrapper‘ in environ:
        return environ[‘wsgi.file_wrapper‘](image, 1024)
    else:
        return iter(lambda: image.read(1024), ‘‘)

http://bbs.ibeifeng.com/read-htm-tid-67892.html

python怎么处理html中的图片,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!