django unicode error on admin page -
i'm vaguely familiar nature of unicode, i'm not sure how pieces fit together. have error when displaying specific instances in admin page.
caught unicodeencodeerror while rendering: 'ascii' codec can't encode character u'\u2019' in position 29: ordinal not in range(128)
here's model:
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) i've gone mysql database , verified db, table, , column collated utf8_unicode_ci, don't understand why page trying render ascii. looking @ various forums , docs, see mention of str , unicode functions, don't seem have list of instances shows fine in on admin page. it's showing actual instance form causes problem.
here's example xml pulled phpmyadmin...
<?xml version="1.0" encoding="utf-8"?> <proposal> <section title="overview"> <section title="introduction"> <text> proposal not in system because completed agreement in word previous getting application , running. please refer attachments in project documentation or see agreement. </text> </section> </section> </proposal> i've tried deliberately exclude xml (which can't in long run since i'd editable in admin section), still same error, i'm not convinced xml problem. if xml isn't problem, have no idea else keeping page being displayed.
class proposaladmin(admin.modeladmin): exclude = ('xml',) admin.site.register(project)
there's ’ character somewhere, in self.project.name. find if check whole error message.
however, if you're getting unicode results database smarter this:
def __str__(self): return ('proposal for: %s' % self.project.name).encode('ascii', errors='replace') the smartest thing do, since it's recommended django documentation, implement __unicode__ function instead:
def __unicode__(self): return u'proposal for: %s' % self.project.name
Comments
Post a Comment