python - 关于falsk一个文件上传的问题
巴扎黑
巴扎黑 2017-04-17 14:53:25
0
1
607

当配置上传目录是
UPLOAD_FOLDER = '/app/uploads'
执行
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
没报错
再执行
@app.route('/uploads/')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'],
filename)
在浏览器上面可以看到图片,但是找不到上传的目录

当配置上传目录是
UPLOAD_FOLDER = 'app/uploads'
执行
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
没报错
再执行
@app.route('/uploads/')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'],
filename)
在浏览器上面开不到图片,但是找到上传目录

关键在于 上传目录的'/'

怎样才能上传了之后在浏览器看到图片,也找到对应的上传目录呢

巴扎黑
巴扎黑

reply all(1)
伊谢尔伦

Under normal circumstances, the first way of writing is recommended, and there is no discussion about whether the second way of writing is right or wrong.

Maybe your system is Windows, and your upload path is written in Linux, which will cause os.path.join exception:

For example: /app/uploads and 1.txt combined:

  • Merged results for Linux: /app/uploads/1.txt
  • Merge results for Windows: /app/uploads.txt
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!