在我的模型中,我定义了这样一个字段:
name = models.CharField(max_length=50)
然后在管理面板中,如果我试图插入一个名为‘č’,‘š’,‘ž’这样的字符的记录,我将得到这个č‘,’š‘,’ž。
'ascii' codec can't encode character u'\u017e' in position 3: ordinal not in range(128)
这是什么?为什么django不使用utf-8来实现一切呢?
发布于 2015-04-03 11:23:09
Django对一切都使用utf-8
。我认为错误可能在模型的__unicode__()
方法中。
您应该始终对所有文本数据使用u'
前缀。所以,如果你写这样的东西:
def __unicode__(self):
return 'Model: %s' % self.name
然后,您需要将其更改为:
def __unicode__(self):
return u'Model: %s' % self.name
https://stackoverflow.com/questions/29431108
复制相似问题