windows python flask上传文件出现IOError: [Errno 13] Permission denied: 'E:\\git\\test\\static\\uploads'的解决...

本文提供了两种解决在浏览器中上传文件时遇到的IOError: [Errno13] Permission denied错误的方法。这两种方法都涉及使用Flask框架进行文件上传处理,并通过调整文件保存路径来避免权限问题。

在浏览器中输入时,出现IOError: [Errno 13] Permission denied: 'E:\\git\\test\\static\\uploads'

http://127.0.0.1:5000/upload

有如下俩种解决方法

1. 第一种

 1 @app.route('/upload',methods=['GET','POST'])
 2 def upload():
 3     if request.method=='POST':
 4         f = request.files['file']
 5         basepath = path.abspath(path.dirname(__file__))
 6         filename = secure_filename(f.filename)
 7         upload_path=path.join(basepath,'static','uploads',filename)
 8         f.save(upload_path)
 9         return redirect(url_for('upload'))
10      return render_template('upload.html')

2. 第二种

1 @app.route('/upload',methods=['GET','POST'])
2 def upload():
3     if request.method=='POST':
4         f = request.files['file']
5         filename = secure_filename(f.filename)
6         f.save(path.join('static/uploads',filename))
7         return redirect(url_for('upload'))
8     return render_template('upload.html')

希望能解决您的问题。

如果有用请点个赞吧!

 

转载于:https://www.cnblogs.com/perl2py/p/6559063.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值