1 回答
TA贡献1803条经验 获得超6个赞
你可以在你的api.py. 这将生成您在屏幕截图中显示的内容:
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework.decorators import api_view, parser_classes
from rest_framework.parsers import FormParser
token = openapi.Parameter('token', openapi.IN_FORM, type=openapi.TYPE_STRING, required=True)
@swagger_auto_schema(
method="post",
manual_parameters=[token]
)
@api_view(["POST"])
@parser_classes([FormParser])
def get_countries(request):
"""
Countries list
"""
......
return Response(countries_list, status=status.HTTP_200_OK)
请注意,我添加了@parser_classes([FormParser])装饰器以确保视图接受表单数据。如果您的所有端点仅使用表单数据并且您在 DRF 设置中全局设置它,您可以将其删除。
结果:

添加回答
举报
