对象ID的Django Unicode引发TypeError:强制转换为Unicode

时间:2018-06-27 11:18:11

标签: python django unicode

我有一个名为UserProfile的Django模型。

这是我的代码:

user_profile = UserProfile.objects.filter(id = 1).first()
if user_profile:
     user_profile_id = user_profile.id
     user_details = 'user id: ' + unicode(user_profile_id)

代码通常可以正常运行,但是今天我在第4行(最后一行)出现了异常:

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

我不知道这里可能出了什么问题。

1 个答案:

答案 0 :(得分:1)

有时SELECT COUNT(id) AS NumResults, race_date AS RaceDate, race_time AS RaceTime FROM results WHere jockeys_claim = 10 GROUP BY race_date DESC, race_time ASC 得到unicode个参数,因此更改代码,

None