diff --git a/docs/api-guide/renderers.md b/docs/api-guide/renderers.md index 685a98f5e..f6e1d07c7 100644 --- a/docs/api-guide/renderers.md +++ b/docs/api-guide/renderers.md @@ -100,18 +100,9 @@ The default JSON encoding style can be altered using the `UNICODE_JSON` and `COM Renders data to HTML, using Django's standard template rendering. Unlike other renderers, the data passed to the `Response` does not need to be serialized. Also, unlike other renderers, you may want to include a `template_name` argument when creating the `Response`. +The `TemplateHTMLRenderer` will create the template context with keys `data`, `request`, `response`, `view` and determine a template name to use to render it. -The TemplateHTMLRenderer will create a `RequestContext`, using the `response.data` as the context dict, and determine a template name to use to render the context. - ---- - -**Note:** When used with a view that makes use of a serializer the `Response` sent for rendering may not be a dictionary and will need to be wrapped in a dict before returning to allow the TemplateHTMLRenderer to render it. For example: - -``` -response.data = {'results': response.data} -``` - ---- +**Note:** For compatibility reasons, the context may contain all response data at the top level as well as the `status_code` key. The template name is determined by (in order of preference): diff --git a/docs/topics/html-and-forms.md b/docs/topics/html-and-forms.md index 18774926b..bc89b73cb 100644 --- a/docs/topics/html-and-forms.md +++ b/docs/topics/html-and-forms.md @@ -17,25 +17,24 @@ Here's an example of a view that returns a list of "Profile" instances, rendered **views.py**: from my_project.example.models import Profile - from rest_framework.renderers import TemplateHTMLRenderer + from my_project.example.serializers import ProfileSerializer + from rest_framework.generics import ListAPIView + from rest_framework.renderers import JSONPRenderer, TemplateHTMLRenderer from rest_framework.response import Response - from rest_framework.views import APIView - class ProfileList(APIView): - renderer_classes = [TemplateHTMLRenderer] + class ProfileListView(ListAPIView): + queryset = Profile.objects.all() + serializer_class = ProfileSerializer + renderer_classes = [JSONPRenderer, TemplateHTMLRenderer] template_name = 'profile_list.html' - def get(self, request): - queryset = Profile.objects.all() - return Response({'profiles': queryset}) - **profile_list.html**: