在接口通讯里经常遇到这种需求,需要将对象的字段名和值均传至接口,user = User.objects.get(id=1)笨方法1,没错,我这样写过:di = {}di['username'] = user.usernamedi['email'] = user.email...... # 诸多赋值笨方法2,没错,我也这样写过:di = {}all_fields = User._meta.get_all_field_names()special_fields = ['is_active', 'is…