根据字段名列表筛选词典。
dictfilter的Python项目详细描述
dictfilter
安装
pip install dictfilter
用法
bsg={'class':'Battlestar','model':'Jupiter','name':'Galactica','crew':{'commander':'William Adama','xo':'Saul Tigh','cag':'Kara Thrace',}}result=query(some_data,['class','name','crew.commander'])# {# 'class': 'Battlestar',# 'name': 'Galactica',# 'crew': {# 'commander': 'William Adama',# }# }
django集成
在settings.py
:
MIDDLEWARE=[...'dictfilter.django.middleware.dictfilter_middleware',]
默认情况下,每个2xx系列响应都将根据查询字符串中以逗号分隔的fields
参数进行筛选。