2017-03-18 7 views
0

強制変換:必要文字列またはバッファ、NoneTypeは...すべてが、これは私のSTRとUnicodeで罰金だと、まだこのエラーを取得

def __str__(self): 
    return '%s' % self.id 

def __unicode__(self): 
    return self.title or u'' 

を発見し、私はすでに

...これを試してみました

def __str__(self): 
    return self.id 

def __unicode__(self): 
    return self.id 
はまだこのエラー..

coercing to Unicode: need string or buffer, NoneType found 

not able to figure it out

を取得します
+0

以下の回答はあなたのために機能しましたか? –

答えて

1

まず、両方の方法を実装する必要はありません。 python 2を使用している場合は、__unicode__を使用してください。 python 3を使用している場合は、__str__を使用してください。

ので、使ってPython 2は、次の操作を行います。Pythonの3のために

def __unicode__(self): 
    return '{}'.format(self.id) 

は、次の操作を行います。私はすでに答えを得た.....しかしのthnxウルrply

のため
def __str__(self): 
    return '{}'.format(self.id) 
0

def __str__(self): 
    return str(self.id) 

def __unicode__(self): 
    return unicode(self.id) 
関連する問題