how to translate Latin characters to Html entities using flask

0

I'm using Flask, to capture a text with an Html form. In the form I have put the acept-encoding=ISO-8859-1 . But when in the form I type a tiny letter, it turns out that through the POST of the form, I get a UNICODE, with ordinal 65533. And of course, I do not know, what coding is giving me back this year Since if in python I do letra=u'ñ' , if you return the code of the eñe in ISO-8859-1 and translate it to an html entity, that would be ñ

So I do not know if the POST does not have the proper encoding, which I do not know if it can be forced in some way. Or is that the Flask internally does some translation. Does anyone know how to translate it to html entities or translate it to the standard encoding of latin1?

    
asked by nauj 03.06.2018 в 13:09
source

1 answer

0

Note . This answer should perhaps be a comment, but it was too long. I will edit it and improve it if I receive more information as detailed below.

There is a lack of data for a definitive answer, but for now I see the following:

  • The header accept-encoding is not related to the coding of the characters, but to the coding of the bytes and basically it is used to specify whether you admit that they are compressed or not, and with what compression format It's irrelevant to your problem.

  • Flask automatically translates to Unicode what it receives from the browser and to know which code table to use, it will look at the header Content-Type: that the browser has sent to it. I suspect therefore that that header is the one that is wrong. Try printing it from flask ( print(request.headers) ).

  • And how does the browser choose which encoding to use? It will use the one that the server indicates through a header <meta> in the HTML. In the absence of this information will use a default value, which may depend on the operative. I think maybe what you need is to put in the header of your HTML (the one that contains the form) the <meta charset="iso-8859-1"> tag.

With this information that I just gave you, you can do some more tests. Report your results to be able to adapt this answer conveniently.

    
answered by 27.11.2018 в 15:56