Python Django ..with unicode and str



我在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, ".")

在 Windows 上所有工作,在服务器上 - ubuntu - 不工作

str.split调用str类上定义的split方法,但您传递它的对象(text)是unicode对象。

幸运的是,split 也是在 unicode 对象上定义的,您可以直接调用它,如下所示:

sentences = text.split(".")

相关内容

最新更新