Christian Schmidt wrote:
> Do I have to encode (or decode) the string before I put it into the
> database

First, it depends on database backend. As far as I know MySQL wants byte 
strings (and for example psycopg2 lives happily with unicode strings). 
If you use newforms then you have data in unicode and you should then 
encode it to put into db. If you don't do this explicitly Python will 
use whatever default encoding is set for this in your environment. It's 
latin-1 in your case and it can't encode "€", this is why you get an error.

The next question is which charset to use for encoding. This depends on 
setup of your database. If it's configured to store data in utf-8 that 
can encode all unicode characters (meaning in practice just all 
characters) then you just encode your unicode strings into utf-8 and all 
will work just fine. If the database configured in some 'old school' way 
using a legacy charset then things get more complicated (can this 
charset also store "€"? can this database accept utf-8 even if it 
doesn't recognize it as such? do you need sorting? will anyone else use 
this database with other client software?).

To summarizes: your storage (a database) and your input/output (the web) 
really should use utf-8 to avoid problems with "strange" characters. If 
you deal internally with unicode (which newforms produce for you) then 
for now you should explicitly encode from it to utf-8 until Django 
starts doing it automatically.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to