Django 1.9.2中的编码错误

时间:2016-02-02 18:53:35

标签: python django

我在数据库中创建了一个模型和两个值。第一个是西里尔语,第二个是拉丁语。

// Set printer settings
ws.PrinterSettings.PaperSize = ePaperSize.Tabloid;
ws.PrinterSettings.Orientation = eOrientation.Landscape;
ws.PrinterSettings.FitToPage = true;
ws.PrinterSettings.FitToHeight = 1;
ws.PrinterSettings.FooterMargin = .05M;
ws.PrinterSettings.TopMargin = .05M;
ws.PrinterSettings.LeftMargin = .05M;
ws.PrinterSettings.RightMargin = .05M;

It seems work fine

但是当我尝试点击链接并编辑西里尔语值时,我收到错误。

ws.Column(30).PageBreak = true;
ws.PrinterSettings.PaperSize = ePaperSize.A3;
ws.PrinterSettings.Orientation = eOrientation.Landscape;
ws.PrinterSettings.Scale = 75;  

1 个答案:

答案 0 :(得分:4)

要在Python 2.7中使用__str__方法而不是__unicode__,请使用提供的python_2_unicode_compatible装饰器:

from __future__ import unicode_literals

from django.db import models
from django.utils.encoding import python_2_unicode_compatible


@python_2_unicode_compatible
class Lecturer(models.Model):
    fname = models.CharField('First name', max_length=200)
    mname = models.CharField('Middle name',max_length=200)
    lname = models.CharField('Last name', max_length=200)
    pub_date = models.DateTimeField('Date published')

    def __str__(self):
        return "{} {} {}" .format(self.fname, self.mname, self.lname)

否则,您必须使用__unicode__而不是__str__