Muh*_*lvi 5 python django django-rest-framework django-rest-swagger
我正在尝试为 Django REST 框架中的 REST API 定义 AutoSchema(将在 django Rest Framework swagger 中显示)。这个类扩展了 APIView。
该类具有“get”和“post”方法。喜欢:
class Profile(APIView):
permission_classes = (permissions.AllowAny,)
schema = AutoSchema(
manual_fields=[
coreapi.Field("username",
required=True,
location='query',
description='Username of the user'),
]
)
def get(self, request):
return
schema = AutoSchema(
manual_fields=[
coreapi.Field("username",
required=True,
location='form',
description='Username of the user '),
coreapi.Field("bio",
required=True,
location='form',
description='Bio of the user'),
]
)
def post(self, request):
return
Run Code Online (Sandbox Code Playgroud)
问题是我想要不同的 get 和 post 请求模式。如何使用 AutoSchema 实现这一目标?
Sab*_*oki -1
如果我正确理解您的问题是什么,您可以在每个方法中定义您的架构,如下所示:
class Profile(APIView):
def get(self, request):
# your logic
self.schema = AutoSchema(...) # your 'get' schema
return
def post(self, request):
self.schema = AutoSchema(...) # your 'post' schema
return
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4584 次 |
| 最近记录: |