V
V
Vadim Klimenko2014-04-30 15:05:24
MySQL
Vadim Klimenko, 2014-04-30 15:05:24

Why does an error occur when saving a Cyrillic string in the Django admin fields?

Hello!
When saving any field through the admin panel in Cyrillic, an error pops up - UnicodeDecodeError ('ascii' codec can't decode byte 0xd0 in position 58: ordinal not in range(128)).
The database is MySQL, which works with Django through the MySQL Connector. OS - Mac OS X. Encoding in the database - UTF-8 everywhere. All files in UTF-8, at the very beginning of the files - # -*- coding: utf-8 -*-. When connecting to the database, the encoding is also indicated.
The code is the most trivial (almost the same as in the Django manuals):
models.py:

# -*- coding: utf-8 -*- 
from django.db import models

class Lesson(models.Model):
  link = models.CharField(max_length=200)
  name = models.CharField(max_length=200)
  pic_id = models.CharField(max_length=200)

admin.py:
# -*- coding: utf-8 -*- 
from django.contrib import admin
from mytests.models import Lesson

admin.site.register(Lesson)

If the string in mysql is already in Cyrillic, then it is displayed perfectly in the admin panel, but when resaving, the same error appears.
I'm learning Django, but I've been tinkering with this error for two weeks now. I rummaged through a ton of questions and answers on this topic, reviewed and tried everything, but, unfortunately, no answer came up.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim Klimenko, 2014-09-09
@Klimenko

There was an error in the connector. With grief, I installed django.db.backends.mysql in half and now it works, everything is saved and works with a bang!

A
Ali Aliyev, 2014-05-01
@ali_aliev

from django.utils.encoding import smart_unicode
class Lesson(models.Model):
....
    def __unicode__(self):
        smart_unicode(return self.name)

try. maybe postgresapp.com will come in handy instead of a muscle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question