Hello,

I am developing a Django application, and have some Unicode problems.
I must admit I do not really understand if my problems are with Django
or Python or ... ; but hopefully someone her can shed some light on
the problem.

Setup:

1. The application is developed for the Scandinavian countries, and
will typically handle various Scandinavian letters like æåø.

2. I am developing everything on Ubuntu Linux.

3. I am using MySQL as database, currently the character_set is set to
(the default) latin-1; but I can of course change that.


What happens:

1. A user fills out a form containing one of the problematic
characters like 'Å'.

2. Django is used to validate the form, and the form content is saved
in the MySQL database.

3. I have a view fetching the content from the database, and returning
it to a users browser with the render_to_response() function.

4. In addition to rendering the template as browser output I want to
store the rendered output in a file (as a hardcopy). This fails with
UnicodeDecodeError. The code which fails look schematically like this:


template = ....
context = ....
string_content = render_to_string( template , context )
fileH = open( filename , "w")
fileH.write( string_content )          <--  This fails.
fileH.close()
....

Now - the code which works exactly as it should, i.e. 3. above, is
nearly identical but the function render_to_output() is used instead,
and no file operations. How does the browser (firefox 3.??) magically
get this right?

I have also tried replacing the write() statement with
write( string_content.encode( 'xxxx' )) where I have tried the
encodings 'latin-1' and 'utf-8'; then it does not fail hard, but
instead of the wanted 'øåæ' characters I get '?' marks.

Any tips on this greatly appreciated.

Joakim





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

Reply via email to