I am working in a Python program with Javascript and DB. I have been having some problems managing the written accent marks (á,é,í,ó,ú). First my program displays some text inputs so the user writes information. When the user clicks an “ACCEPT” button, a javascript takes that information and sends it to another python program which is going to save that information on a database. The next time the user enters, the info saved on the database would be displayed instead of the text inputs.
My problem is when the information has any accent mark on it. At first I though it was a problem with javascript so I start working on replaces functions. Then i saw that the information was saved on the database with the accent mark, so the problem is not with the javascript function, or the database.
The information is taken from the database and it displays the accent marks very well. Then a javascript takes that value and if I put an alert with that value, it displays the accent mark very well. That javascript sends that value on a URL with AJAX to another python program. This python receives that value but when print it, it is modify. The accent mark is not longer displayed, but a little square. I receive the values with this code (I have been using this many times):
form = cgi.FieldStorage()
area = form.getfirst("area")
So i started tasting again the python replace function to change that character to the apropiate accent mark. I been trying something like: area.replace("\u00e9","é") for (é). But it does not work.
I also have this in my programs: # -*- coding: iso-8859-1 -*- which works for special characters.
I need to find out the way python represents the accents so I can replace them.
You need to back up here.
Set a coding of utf-8 (
# -*- coding: utf-8 -*-), and use an editor that works with unicode.Declare your constants, and generally operate with, unicode strings like
u'hélas'.As if by magic, accents will work (as long as your database handles unicode correctly; ensure that it does).