【发布时间】:2010-01-06 08:12:51
【问题描述】:
在我的 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 使用其他东西并安全地检索对象?
【问题讨论】:
-
你能发布你的演示模型的colde吗?
标签: python django unicode django-admin