在Django管理中保存对象时出现Unicode错误
在我的django应用程序中,我有一些对象导致django
admin中的相应URL为非ascii。(例如:http://mysite/admin/myapp/myclass/Présentation/
)
我可以毫无问题地编辑对象,但是在保存时出现以下错误:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position
24: ordinal not in range(128), HTTP response headers must be in US-ASCII
format
奇怪的是,该对象已正确保存到数据库中。
有人知道Django管理员如何管理unicode吗?任何有助于解决此问题的信息,指针或想法将不胜感激。
提前致谢
更新:这是模型的代码
class Plugin(models.Model):
"""Some subcontent that can be added to a given page"""
class Meta:
ordering = ['ordering']
name = models.CharField(max_length=32, primary_key=True)
div_id = models.CharField(default='rightcol', max_length=32)
published = models.BooleanField(default=True,
help_text=_("If this is not checked, it is not displayed on the page."))
ordering = models.IntegerField(default=1,
help_text=_("plugins are sorted with this number in ascending order"))
content = models.TextField(blank=True)
registration_required = models.BooleanField(_('registration required'),
help_text=_("If this is checked, only logged-in users will be able to view the page."))
def __unicode__(self):
return u"%s -- %s" % (self.name, self.div_id)
更新:很明显,URL中不建议使用非ASCII字符。那就是我的问题的原因,我已经改变了。
是否有人知道Django管理员用来构建对象URL的内容。我猜这是主键。这样对吗?有没有办法强迫Django使用其他东西并安全地检索对象?