这是我的app / views.py
class ExampleView(APIView):
def get(self, request, format=None):
print(request.META['HTTP_HEADER']) # Want this header from swagger ui
snippets = Snippet.objects.all()
serializer = SnippetSerializer(snippets, many=True)
return Response(serializer.data)
def post(self, request, format=None):
serializer = SnippetSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
app / serilaizers.py
class SnippetSerializer(serializers.ModelSerializer):
class Meta:
model = Snippet
fields = ('id', 'title', 'code', 'linenos', 'language', 'style', 'owner')
swagger UI的当前屏幕截图,因为没有用于标题参数和后置参数的字段。
版本:
django-rest-swagger == 2.1.0
djangorestframework == 3.9.1