------------------
Hi all, I'm from China and have recently been studying turbogears. I hope this will help people from countries where languages other than English are spoken. Please point out any mistakes. Each message will be short, but I will keep replying to this thread frequently.
TIP 1.
Better use utf-8 in kid files.
TIP 2.
If a column might contain non utf-8 characters, define it like this in model.py:
UnicodeCol(dbEncoding = "gb2312")
TIP 3.
You want to use standard widgets but you find it doesn't work with Chinese! Then you should:
- Add this at the top of your code: # -*- coding: utf-8 -*-
- Convert your source file to utf-8
- Add a u before any string that contains a Chinese character. (this third one is a must!)
TIP 4.
Something interesting. If you have ever tried the 20 minutes wiki tutorial, run it and type something like this in your browser's address box.:
http://localhost:8080/一些中文字符
Press Enter. As the page does not exist, you will reach the Edit page. Input some text and then save.
Oops! Something wrong happened but if you check the database you will see a new page has been added. This might be a bug, I will see if I have time to fix it.
TIP 5.
If you are using MySQL on windows, use MySQL-python.exe-1.2.2b1.win32-py2.4.exe or you will encounter big problems when you want to execute some SQL containing Unicode.
TIP 6.
If you are using mysql, change your dburi to this form:
sqlobject.dburi="mysql://username:password@hostname:port/databasename?charset=utf8&sqlobject_encoding=utf8
The first encoding tells MySQLdb what charset mysql should use, the second one tells sqlobject how to give MySQLdb a unicoded sql.
TIP 7.
Remarks on TIP 6.
When you're using mysql, you have to use byXXX functions like this:
user = User.byName(u'UserName'.encode('gb2312'))Unicode strings are not accepted. That's why you need to include sqlobject in your dburi.
That's definitely a bug of sqlobject.
If you want a fixed version, you should use CVS to get the latest version.

没有评论:
发表评论