# -*- coding: utf-8 -*-
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class Label(models.Model):
width = models.ForeignKey(PaperWidth, verbose_name='宽度')
height = models.ForeignKey(PaperHeight, verbose_name='高度')
def __str__(self):
return u'{0}({1}×{2})'.format(self.paper_type, self.width, self.height)
这个是一个 python 2.7,django1.8 的程序
之前 verbose_name=u'宽度' 在添加 @python_2_unicode_compatible 就去掉u了,没有问题
但下面的 return u'{0}({1}×{2})' 为什么不能去掉呢?去掉就报错
'ascii' codec can't decode byte 0xe9 in position 0