Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.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在数据库中插入utf8字符_Python_Django_Utf 8_Django Views - Fatal编程技术网

Python 使用Django在数据库中插入utf8字符

Python 使用Django在数据库中插入utf8字符,python,django,utf-8,django-views,Python,Django,Utf 8,Django Views,在Django中,插入数据库时如何使用unicode 例如: name =request.POST["name"] //This may be in Chinese or any other lanuages usr = Users(name=name) usr.save() Cent os中使用的Python版本是Python 2.4.3,mod Python版本是1.2.1_p2-1使用unicode(“某些字符串”)以unicode格式将字符串发

在Django中,插入数据库时如何使用unicode

例如:

       name =request.POST["name"] //This may be in Chinese or any other lanuages
       usr = Users(name=name)
       usr.save()

Cent os中使用的Python版本是Python 2.4.3,mod Python版本是1.2.1_p2-1

使用unicode(“某些字符串”)以unicode格式将字符串发送到DB。您可能对数据库有不同的设置,但它没有与Django连接。

您使用的是什么数据库?如果是MySQL,请确保遵循上的Django文档。

您应该检查您的数据库在您尝试插入的表上是否有utf8字符集

对于mysql

show create table TableName;
更改编码

   alter table TableName DEFAULT CHARACTER SET utf8;

你试过了吗?是的..usr.save()上有一个错误。我也试着用SafeUnicode来做这件事。但是内容不会被插入数据库。这是为了对我的python版本做些什么吗?什么样的错误?请粘贴它。是否确实为UTF8设置了数据库?第1行“代码”列的字符串值不正确:'\xE4\xA45\xB34\xE0\xH4\x0…'