I have a string which instead of the byte <27> (hexadecimal) to represent ' (apostrophe), uses the three bytes <E2><80><99>. Firefox displays this as an apostrophe, but when passed through Django’s render_to_response function, I get ’. Same goes for some other characters: <E2><80><A6> to represent ... (elipsis) and <E2><80><93> instead of -. Is there a name for this three-byte representation that Firefox seems to understand?
Where ‘mydata’ contains the string:
render_to_response(mytemplate, mydata, mycontext)
and
render_to_response(mytemplate, mydata, mycontext, mimetype='text/html')
works except for the funny characters
render_to_response has a mimetype parameter which I might be able to use if I know what the MIME type of my file is. I have tried
render_to_response(mytemplate, mydata, mycontext, mimetype='application/xhtml+xml')
Which doesn’t throw any exceptions it just never returns.
I have two questions: (1) What is the name of the character encoding my HTML file is using. (2) Will the mimetype parameter be able to help me render this the way I want it?
It’s UTF-8, which you should decode to a
unicodebefore sending in a response.