判断提交的表单中是否包含中文字
作者:半瓶墨水 链接:http://www.2maomao.com/blog/python-chinese-encode/
Some Chinese Please是用php写的wordpress插件。
基本原理是:英文spammer比较多,如果评论中没有中文字默认为spammer
上网查了一下Python做这个的代码,逻辑比较复杂,想了想,做了个判断是否包含非英语文字的:
str = comment.encode('utf-8')
if len(str) == len(comment):
raise forms.ValidationError('评论中必须包含中文字')
if len(str) == len(comment):
raise forms.ValidationError('评论中必须包含中文字')
应该有作用。
共 2 条评论
发表评论
Additional comments powered by BackType



test通过- -
@VespertineR
啥意思?呵呵我没有在这个blog上应用python的那个方法呀。