@register.filter(name='to_name')
def to_name(user_id):
 try:
  user = User.objects.filter(id=int(user_id))
  if user:
   user = user[0]
   return user.name
 except:
  return '\xe9\x9d\x9e\xe6\xb3\x95\xe7\x94\xa8\xe6\x88\xb7'

@ register . filter ( name = 'to_name' ) def to_name ( user_id ) : try : user = User . objects . filter ( id = int ( user_id ) ) if user : user = user [ 0 ] return user . name except : return '\xe9\x9d\x9e\xe6\xb3\x95\xe7\x94\xa8\xe6\x88\xb7'
user id 转位用户名称 .