我遇到了问题所以问题是我有一个DetailView。当找不到对象时,我得到:
'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
The string that could not be encoded/decoded was: ��quip
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\views\generic\base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\generic\base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\generic\detail.py" in get
110. self.object = self.get_object()
File "C:\Python27\lib\site-packages\django\views\generic\detail.py" in get_object
55. {'verbose_name': queryset.model._meta.verbose_name})
Exception Type: UnicodeDecodeError at /teams/arsenal-3-66/
Exception Value: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
这样做而不是返回404 ....
我不知道该怎么做。
详情视图很简单:
class TeamDetailView(generic.DetailView):
model = Team
template_name = 'teams/team.html'
模型也很简单:
class Team(models.Model):
name = models.CharField(max_length=25,verbose_name=_("name"))
slug = AutoSlugField(unique=True,populate_from='name')
class Meta:
verbose_name = 'Équipe'
verbose_name_plural = 'Équipes'
def __unicode__(self): # Python 2.7: def __unicode__(self):
return self.name
谢谢, ARA
答案 0 :(得分:1)
这是一个愚蠢的错误。
我所要做的就是:
class Meta:
verbose_name = u'Équipe'
verbose_name_plural = u'Équipes'