I have the following generic class based views built with Django Rest framework (DRF)
class ExampleDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Example.objects.all()
serializer_class = ExampleSerializer
renderer_classes = (JSONRenderer, TemplateHTMLRenderer)
def get(self, request, *args, **kwargs):
response = self.retrieve(request, *args, **kwargs)
if request.accepted_renderer.format == 'html':
form = ExampleForm(data=response.data)
return Response({'data': response.data, 'form': form}, template_name='example.html')
return response
This view allow me to obtain both JSON data or HTML form from the same endpoint by specifying the format=json or html.
I would like to programmatically call that view to obtain the rendered HTML form from within another view in order to include this form in another page that will include more stuff.