E
E
Eugene5232019-12-24 22:13:52
Django
Eugene523, 2019-12-24 22:13:52

Wrong encoding in when displaying in Django admin?

I have a simple model:

class Profession(models.Model):
    name = models.CharField(max_length=64, help_text="Название профессии")

I decided to write a script to populate the database with mock records.
Here is the script:
from employeeapp.models import Profession, Employee
p = Profession(name=u'Няня')
p.save()

I call the script as follows:
python manage.py shell < mockfill.py
After execution, the name is displayed in the wrong encoding:
5e026061a8d25035834142.png
I tried both simple and - everything is the same, it is displayed in the wrong encoding. If on the command line I call: and then I start manually typing:name='Няня'name=u'Няня'
python manage.py shell < mockfill.py
>>> from employeeapp.models import Profession
>>> p = Profession(name='Няня')
>>> p.save()

then the result is correct:
5e0261aa7a58a741981099.png
It is clear that the error is in the encoding. But where? In a script file? In console settings?
If that I use VS Code. It says UTF-8 at the bottom.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
antonksa, 2019-12-24
@antonksa

Vendian coders must suffer.

E
Eugene523, 2019-12-24
@Eugene523

Found a way out:
call:
and then execute:

>>> exec(open("mockfill.py", encoding="utf-8").read())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question