Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting utf8 characters in DB using Django

In Django how to use unicode when inserting into DB

Example:

       name =request.POST["name"] //This 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

like image 243
Rajeev Avatar asked Dec 06 '25 07:12

Rajeev


1 Answers

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;
like image 114
damir Avatar answered Dec 07 '25 20:12

damir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!