DRF YASG Настройка

Вместо нижней строки

//header("Location:".ADMIN_URL."/index.php");

напишите

echo("<script>location.href = '".ADMIN_URL."/index.php?msg=$msg';</script>");

или

?><script><?php echo("location.href = '".ADMIN_URL."/index.php?msg=$msg';");?></script><?php

Это определенно решит вашу проблему. Я столкнулся с одной и той же проблемой, но решил решить эту проблему путем написания заголовка.

2
задан Joseph Groot Kormelink 5 March 2019 в 16:26
поделиться

1 ответ

В настоящее время я использую APIView и @swagger_auto_schema для определения документации моей конечной точки.

В приведенном ниже коде вы можете увидеть, как добавить дополнительную информацию для определения вашей конечной точки. Я надеюсь, что это поможет вам

##serializers.py

class CategorySerializer(serializers.ModelSerializer):
    """
    Serializing Categories 
    """
    class Meta:
        model = Category
        fields = [
            'id', 'name', 'slug'
        ]
        read_only_fields = [
           'slug', 
        ]


##views.py

username_param = openapi.Parameter('username', in_=openapi.IN_QUERY, description='Username',
                                type=openapi.TYPE_STRING)
email = openapi.Parameter('email', in_=openapi.IN_QUERY, description='Email',
                                type=openapi.TYPE_STRING)  
category_response = openapi.Response('response description', CategorySerializer)    

class CategoryList(APIView):
    permission_classes = [AllowAny]

    @swagger_auto_schema(
        manual_parameters=[username_param, email],
        query_serializer=CategorySerializer,
        responses = {
            '200' : category_response,
            '400': 'Bad Request'
        },        
        security=[],
        operation_id='List of categories',
        operation_description='This endpoint does some magic',
    )
    def get(self, request, format=None):
        """
        GET:
        Return a list of all the existing categories.
        """
        categories = Category.objects.all()
        serializer = CategorySerializer(categories, many=True)
        return Response(serializer.data)


    @swagger_auto_schema(
        request_body=CategorySerializer,
        query_serializer=CategorySerializer,
        responses={
            '200': 'Ok Request',
            '400': "Bad Request"
        },
        security=[],
        operation_id='Create category',
        operation_description='Create of categories',
    )
    def post(self, request, format=None):
        """
        POST:
        Create a new category instance.
        """
        serializer = CategorySerializer(data=request.data)
        if serializer.is_valid():
            serializer.save(created_by=self.request.user)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Наконец, если вы хотите увидеть свои конечные точки в группах по ссылке, вы можете протестировать комментирование строки ниже в вашем urls.py

#urlpatterns = format_suffix_patterns(urlpatterns)

Ниже приведен экран того, как вы должны его видеть

[home][1]
[Get all categories][2]
[Post a new category][3]
[Endpoints in groups][4]

You can find more information in the link below

https://drf-yasg.readthedocs.io/en/stable/custom_spec.html

  [1]: https://i.stack.imgur.com/iwsnB.png
  [2]: https://i.stack.imgur.com/R7f1q.png
  [3]: https://i.stack.imgur.com/1ia9F.png
  [4]: https://i.stack.imgur.com/Gwckf.png
0
ответ дан Samir 5 March 2019 в 16:26
поделиться
Другие вопросы по тегам:

Похожие вопросы: