B
B
blazer052016-03-25 11:12:46
Django
blazer05, 2016-03-25 11:12:46

How to solve 'ascii' encoding error?

There was a problem, when deleting news, an encoding exception appears.
16007bcfd21a4cf5a990277871000c57.jpg
More details

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Voronkov, 2016-03-25
@DmitryVoronkov

Try like this:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models


class Category(models.Model):
    name = models.CharField(max_length=32, verbose_name='Наименование')

    class Meta:
        verbose_name = 'Категорию'
        verbose_name_plural = 'Категории'

    def __unicode__(self):
        return unicode(self.name)
    
    def __str__(self):
        return self.__unicode__()

I
Igor Gorshal, 2016-04-18
@neegor

Look aside https://docs.djangoproject.com/ja/1.9/ref/utils/#m... or switch to python3 (unicode is a good reason).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question