webpy学习之serving images
2015-08-24 11:43
176 查看
</pre><p>1,新建文件目录../serving_images/,在该目录下面新建文件serving_images.py,文件内容如下:</p><p></p><p></p><pre name="code" class="python">mport web import os urls = ( '/images/(.*)', 'images' #this is where the image folder is located.... ) class images: def GET(self,name): ext = name.split(".")[-1] # Gather extension #<span style="color:#33FF33;">返回获取的所有子字符串</span> cType = { "png":"images/png", "jpg":"images/jpeg", "gif":"images/gif", "ico":"images/x-icon" } if name in os.listdir('images'): # Security web.header("Content-Type", cType[ext]) # Set the Header return open('images/%s'%name,"rb").read() # Notice 'rb' for reading images else: raise web.notfound() app = web.application(urls, globals()) if __name__ == '__main__': app.run()
在../serving_images/目录下创建images/目录,将你想要显示的图片放到该目录下,注意文件格式。然后,
python serving_images.py
登陆http://localhost:8080/image_name.png,即可提供图片下载查看功能。
相关文章推荐
- Rendering Linear lighting and color
- 色彩校正中的 gamma 值是什么?
- JAVA I/O使用方法
- SharePoint 2013 IT Professional——如何部署My Site
- [教程]DLL注入的方法及通讯[2009-8-14]
- intel编译器编译cp2k
- TCP 出现大量 LAST_ACK 导致apache不能重启解决小结
- css学习选择器之:nth-child(n)
- android真机开发连接javaWeb后台服务器
- 软件测试中的那些不可遗忘的基础知识
- unity3d 脚本的一些简单介绍
- WebLogic11g-半小时让你的domain集群化
- 创建Xml文件与修改Xml文件
- Linux文件传输scp和rsync断点续传
- LeetCode "Read N Characters Given Read4 II - Call multiple times"
- js创建对象的几种方式
- Spring Security Custom Login Form Example
- 访园助手ios端项目小结
- git stash
- ubuntu14.10 tftp服务配置20150824