H4k*_*kor 3 django unicode ascii admin utf-8
当我尝试查看现有对象列表时,我在管理页面上收到以下错误.
UnicodeEncodeError at /admin/character/charlevel/
'ascii' codec can't encode character u'\xd6' in position 0: ordinal not in range(128)
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/character/charlevel/
Django Version: 1.4.1
Exception Type: UnicodeEncodeError
Exception Value:
'ascii' codec can't encode character u'\xd6' in position 0: ordinal not in range(128)
Exception Location: /home/***/workspace/***/***/character/models.py in __unicode__, line 413
Python Executable: /usr/bin/python
Python Version: 2.7.3
Run Code Online (Sandbox Code Playgroud)
当我打开这个类的对象列表时会发生这种情况:
class CharLevel(models.Model):
char = models.ForeignKey(Character)
prof = models.ForeignKey(Profession)
level = models.SmallIntegerField()
def __unicode__(self):
return ('{c}/{l}/{p}'.format(c=self.char.name, l=self.level, p=self.prof )).encode('utf-8')
Run Code Online (Sandbox Code Playgroud)
如果我删除{c}字符串格式的组件,问题就会消失
但是,Charater类不会出现以下问题__unicode__:
class Character(models.Model):
name = models.CharField(max_length=32)
def __unicode__(self):
return self.name
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
Pav*_*sov 12
__unicode__应该返回unicode:
def __unicode__(self):
return u'{c}/{l}/{p}'.format(c=self.char.name, l=self.level, p=self.prof)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4312 次 |
| 最近记录: |