【发布时间】:2011-09-27 11:06:00
【问题描述】:
我对 unicode 的性质有点熟悉,但我不确定所有部分是如何组合在一起的。在管理页面中显示特定实例时出现错误。
捕获 UnicodeEncodeError 而 渲染:“ascii”编解码器无法编码 第 29 位的字符 u'\u2019': 序数不在范围内(128)
这是我的模型:
class Proposal(models.Model):
project = models.ForeignKey(Project)
dateCreated = models.DateTimeField(editable=False)
xml = models.TextField(max_length=1000000)
def __str__(self):
return str('Proposal for: %s' % self.project.name)
我已经进入我的 mysql 数据库并验证了 DB、表和列都被整理为 utf8_unicode_ci,所以我不明白为什么页面试图呈现为 ascii。查看各种论坛和文档,我看到提到了 str 和 unicode 函数,但它们似乎与此无关,因为实例列表显示在管理页面上很好。它只是显示导致问题的实际实例形式。
这是我从 phpmyadmin 中提取的一些示例 xml...
<?xml version="1.0" encoding="UTF-8"?>
<proposal>
<section title="OVERVIEW">
<section title="Introduction">
<text>
This proposal is not in the system because it was completed as an agreement in Word previous to us getting this application up and running. Please refer to the attachments in this project for documentation or to see the agreement.
</text>
</section>
</section>
</proposal>
我什至试图故意排除 xml(从长远来看我不能这样做,因为我希望它可以在管理部分进行编辑),但我仍然遇到同样的错误,所以我我甚至不相信 xml 甚至是问题所在。如果 xml 不是问题,我不知道还有什么可以阻止此页面显示。
class ProposalAdmin(admin.ModelAdmin):
exclude = ('xml',)
admin.site.register(Project)
【问题讨论】:
标签: django unicode django-admin