drf GenericAPIView类属性lookup_field的作用

在这里插入图片描述

lookup_field - The model field that should be used to for performing object lookup of individual model instances. Defaults to
‘pk’. Note that when using hyperlinked APIs you’ll need to ensure that
both the API views and the serializer classes set the lookup fields if
you need to use a custom value.

GenericAPIView中实现了一些方法比如get_objects可以直接调用获取实例对象,lookup_field默认值是指定model的primary_key,用户也可以自己指定。之后get_objects就通过lookup_field去检索对象。

参考
drf文档中文翻译—router部分
drf文档中文翻译—Viewset视图集部分
lookup_field的作用

猜你喜欢

转载自blog.csdn.net/qq_42648305/article/details/112748577
DRF
今日推荐