Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Django@schema(自动模式)中设置对象(手动字段=_Python_Django_Django Rest Framework_Django Views - Fatal编程技术网

Python 在Django@schema(自动模式)中设置对象(手动字段=

Python 在Django@schema(自动模式)中设置对象(手动字段=,python,django,django-rest-framework,django-views,Python,Django,Django Rest Framework,Django Views,我正在使用django rest api,该api接收端点中的对象 有些对象属性是必需的,有些则不是 我想在文档中显示这一点,但我不知道如何使用手动字段显示对象 现在我只有对象的名称,如: @schema(AutoSchema(manual_fields=[ coreapi.Field("node", required=True, location="query", description="Node Object") ])) 文档中显示了这一点,如下所

我正在使用django rest api,该api接收端点中的对象

有些对象属性是必需的,有些则不是

我想在文档中显示这一点,但我不知道如何使用手动字段显示对象

现在我只有对象的名称,如:

@schema(AutoSchema(manual_fields=[
        coreapi.Field("node", required=True, location="query", description="Node Object")        
    ]))
文档中显示了这一点,如下所示:


使用coreschema设置描述

from rest_framework.compat import coreschema

coreapi.Field(
    name=name, required=required, location=location, 
    schema=coreschema.String(title=name, description=description)
)

使用coreschema设置描述

from rest_framework.compat import coreschema

coreapi.Field(
    name=name, required=required, location=location, 
    schema=coreschema.String(title=name, description=description)
)