Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango legacy database encoding
    primarykey
    data
    text
    <p>I'm sure this question is not specific to django, but since I couldn't find any solution for my problem in other questions about python and encodings, I'm going to ask this. I need to add new features to existing website which is written in PHP using MySQL as backend. I inspected the database and created models for tables I am going to use. However, there is a problem with the existing data- half of it is in russian, and (at least it seems to me) it's in utf-8 encoding. When I show that data in django's admin, it doesn't appear right.</p> <pre><code>In [52]: p.name Out[52]: u'\xd0\u02dc\xd0\xb3\xd0\xbe\xd1\u20ac\xd1\u0152 ' In [53]: repr(p.name) Out[53]: "u'\\xd0\\u02dc\\xd0\\xb3\\xd0\\xbe\\xd1\\u20ac\\xd1\\u0152 '" </code></pre> <p>In django admin it displays like this:</p> <pre><code>Игорь </code></pre> <p>Encodings are still a little bit mythical for me, but if I understand this output correctly, basically those are utf-8 bytes in unicode object.</p> <p>The question: is it possible to fix this in django's database layer? I'm going to update existing content in these tables, and I need the existing PHP front-end to be compatible with both the new data and old one.</p> <p>When I add these database options data is displayed in admin correctly, <strong>however, I get UnicodeEncode error when saving something.</strong></p> <pre><code>DATABASE_OPTIONS = { 'charset': 'latin1', 'use_unicode': False, } </code></pre> <p>Name returned in this case is:</p> <pre><code>In [2]: p2.name Out[2]: '\xd0\x9b\xd0\xae\xd0\xa1\xd0\xaf' </code></pre> <p>I checked with utf-8 character table, and those are correct characters for the data stored in that row.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload