W
W
Wizzy2016-09-02 12:32:33
Django
Wizzy, 2016-09-02 12:32:33

Django. How to change encoding from ascii to utf-8?

Python 3.5
Django 1.10
Making a POST request: Trying to display the received value: Getting an error:
description = request.POST.get('description', '')
print(description)

'ascii' codec can't encode characters in position 93-98: ordinal not in range(128)

I tried to add in settings.py
DEFAULT_CHARSET = 'utf-8'

Tell me what to do?
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tash1moto, 2016-09-02
@Tash1moto

try like this
description.encode( "utf-8" , "ignore")

A
Andrey Voskresensky, 2016-09-03
@Voskresenskyi

class Blog (models.Model):
    title = models.CharField(max_length=100, verbose_name="Все категории")

    def __str__(self):
        return self.title

you can explicitly convert the type of the object to a string and get everything right!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question