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