coercing to Unicode: need string or buffer, NoneType found when rendering in django admin

后端 未结 6 633
梦毁少年i
梦毁少年i 2020-12-07 22:32

I have this error since a long time but can\'t figure it out :

Caught TypeError while rendering: coercing to Unicode: need string or buffer, NoneType found

6条回答
  •  不思量自难忘°
    2020-12-07 22:48

    This error happens when you have a __unicode__ method that is a returning a field that is not entered. Any blank field is None and Python cannot convert None, so you get the error.

    In your case, the problem most likely is with the PCE model's __unicode__ method, specifically the field its returning.

    You can prevent this by returning a default value:

    def __unicode__(self):
       return self.some_field or u'None'
    

提交回复
热议问题