django - 如何访问 Django Rest Framework 3.0 序列化程序中的查询参数?

标签 django django-rest-framework

例如,在 Django Rest Framework 2.x 中,您可以访问序列化程序中的“字段”查询参数,如下所示:

   fields = self.context['request'].QUERY_PARAMS.get('fields')

这在 DRF 3.0 中不再有效,但除一般术语外,我找不到 API 中记录的更改。看起来它可能类似于 self.context.get('request')?????但我想不通。

你会如何在 DRF 3.0 中做到这一点?我说的是在序列化程序中而不是在 View 中访问 query.params。

谢谢

约翰

最佳答案

这是 DRF 3:

fields = self.context.get('request').query_params.get('fields')

关于django - 如何访问 Django Rest Framework 3.0 序列化程序中的查询参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28653919/

相关文章:

python - django 创建自定义 shell 命令以创建具有自定义布局的应用程序

android - 无法通过 Android 应用程序访问笔记本电脑的本地主机

python - 对 List 和 Retrieve Rest API 使用一个基于类的 View

django - 名称错误 : name 'Model' is not defined after importing models in a newly created file

Django 查询 : how to filter objects to exclude id which is in a list?

python - Django REST 框架 : nested relationship: non_field_errors

python - 断言错误 : `create()` did not return an object instance

django - JWT 身份验证不适用于 Django 中的自定义 Controller

python - Django-CMS 模板 block

python - 导入错误 : No module named rest_framework. 授权 token