-
检测文件名中是否包含中文
- def is_chinese(char):
- """判断是否包含中文"""
- if not isinstance(char, unicode):
- char = char.decode('utf8')
- if re.search(ur"[\u4e00-\u9fa5]+",char):
- return True
- else:
- return False
检测文件名中是否包含空格
- def is_space(char):
- """判断是否包含空格"""
- if re.search(ur"\s",char):
- return True
- else:
- return False
调用函数,进行检测,update_files是包含很多文件名的列表,检测完毕后,返回给前端模板,模板会显示result_files和message:
-
- result_files = []
- for file in update_files:
- if is_chinese(file):
- result_files.append(file)
- if is_space(file):
- result_files.append(file)
- if result_files:
- message = u'文件名中带有空格,或带有中文,不符合规范,请修改!'
- return render(request,'yxl_front.html',locals())