Python Django..使用unicode和str
我的Django网站有问题 在我的电脑里,我在Windows上使用了PyCharm——一切正常。表单数据=str,在我的服务器上=unicode 我的服务器上出现错误:Python Django..使用unicode和str,python,django,Python,Django,我的Django网站有问题 在我的电脑里,我在Windows上使用了PyCharm——一切正常。表单数据=str,在我的服务器上=unicode 我的服务器上出现错误: TypeError at /result descriptor 'split' requires a 'str' object but received a 'unicode' 我的代码: text = request.POST['text'] sentences = str.split(text, ".") 在Window
TypeError at /result
descriptor 'split' requires a 'str' object but received a 'unicode'
我的代码:
text = request.POST['text']
sentences = str.split(text, ".")
在Windows all work上,在服务器上-ubuntu-not work
str.split
正在调用在str
类上定义的split
方法,但是您传递它的对象--text
--是unicode
对象
幸运的是,split
也定义在unicode
对象上,您可以直接调用它,如下所示:
sentences = text.split(".")