Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django..使用unicode和str_Python_Django - Fatal编程技术网

Python Django..使用unicode和str

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

我的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 all work上,在服务器上-ubuntu-not work

str.split
正在调用在
str
类上定义的
split
方法,但是您传递它的对象--
text
--是
unicode
对象

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

sentences = text.split(".")