Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Pass 'user' to template explicitly
  • Loading branch information
lovelydinosaur committed Jun 1, 2016
commit 437a12579394ef65f67c4752e6a8a8992c31e9dc
1 change: 1 addition & 0 deletions rest_framework/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ def get_context(self, data, accepted_media_type, renderer_context):
'view': view,
'request': request,
'response': response,
'user': request.user,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed by Django 1.10 ?

Copy link
Contributor Author

@lovelydinosaur lovelydinosaur Jun 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For one reason or another, yes.

I've not dug into why yet, but presumably we were previously having it automatically included by the RequestContext. I assume that we could also change our settings in order to resolve this (eg perhaps context processor configuration has moved to being part of the TEMPLATES dictionary?)

In any case it's probably best that we pass it explicitly, rather than relying on the correct context processors being set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified. Previously we were relying on the default value of TEMPLATE_CONTEXT_PROCESSORS, which includes django.contrib.auth.context_processors.auth.

We could add this in to the TEMPLATES.OPTIONS.context_processors in conftest.py, which would resolve our test cases, but it's better if we pass it explicitly, and not rely on the user settings.

'description': self.get_description(view, response.status_code),
'name': self.get_name(view),
'version': VERSION,
Expand Down
3 changes: 1 addition & 2 deletions tests/browsable_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@


class MockView(APIView):

authentication_classes = (authentication.SessionAuthentication,)
renderer_classes = (renderers.BrowsableAPIRenderer,)
renderer_classes = (renderers.BrowsableAPIRenderer, renderers.JSONRenderer)

def get(self, request):
return Response({'a': 1, 'b': 2, 'c': 3})