flask中的secure_filename方法获取不到中文文件名

在使用Flask时遇到一个问题,当尝试用secure_filename处理包含中文的文件名时,中文部分被过滤只剩后缀。原因是werkzeug库的此方法不支持中文。解决方案包括避免使用中文文件名或自定义secure_filename方法的实现。
摘要由CSDN通过智能技术生成

碰到以下问题:
将中文文件名传给 secure_filename 方法时所有的中文名都会被过滤掉,只剩下文件后缀名。
原因:werkzeug库的secure_filename方法中,中文被ignore或者压制导致数据缺失
解决方法:
1,要么更换或弃用中文文件名
2,视情况修改secure_filename方法的代码

def secure_filename(filename):
    r"""Pass it a filename and it will return a secure version of it.  This
    filename can then safely be stored on a regular file system and passed
    to :func:`os.path.join`.  The filename returned is an ASCII only string
    for maximum portability.

    On windows systems the function also makes sure that the file is not
    named after one of the special device files.

    >>> secure_filename("My cool movie.mov")
    'My_cool_movie.mov'
    >>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值