python django 上传图片

  1. 安装PIL模块,如果你的电脑是windows的话,64位的下载地址为http://www.lfd.uci.edu/~gohlke/pythonlibs/ 安装命令:pip install *.whl

  2. 如果你的电脑是linux的话直接下载http://www.pythonware.com/products/pil/ 安装即可

  3. 前台代码

<input type="file" name="image">

4.后台代码

reqfile= request.FILES['image']     

image =Image.open(reqfile)  

image.thumbnail((520,520),Image.ANTIALIAS)      //保存大小                                                            

image.save("D:\\data\\admin\\static\\images\\login.jpeg","jpeg")#所有的文件都是以login.jpeg保存


你可能感兴趣的:(django,python,上传图片)