开发者

Inserting utf8 characters in DB using Django

开发者 https://www.devze.com 2023-01-07 03:50 出处:网络
In Django how to use unicode when inserting into DB Example: name =request.POST[\"name\"] //This 开发者_StackOverflow社区may be in Chinese or any other lanuages

In Django how to use unicode when inserting into DB

Example:

       name =request.POST["name"] //This 开发者_StackOverflow社区may be in Chinese or any other lanuages
       usr = Users(name=name)
       usr.save()

The Python version that is used in Cent os is python 2.4.3 and mod python version is 1.2.1_p2-1


you should check if your database has utf8 charset on table in which you are trying to insert.

for mysql

show create table TableName;

to change encoding

   alter table TableName DEFAULT CHARACTER SET utf8;


What database are you using? If it's MySQL, make sure you follow the Django documentation on creating UTF-8 compatible MySQL databases.


Use unicode('some string') in order to send the string to DB in Unicode. You might have different settings for the DB, but this is not connected with Django.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号