Use 'results' key in TemplateHTMLRenderer when data is a list#9972
Open
jesustorres-code wants to merge 1 commit into
Open
Use 'results' key in TemplateHTMLRenderer when data is a list#9972jesustorres-code wants to merge 1 commit into
jesustorres-code wants to merge 1 commit into
Conversation
…plateHTMLRenderer When TemplateHTMLRenderer.get_template_context() receives list data (from a list view or a ValidationError), it wraps it in a dict so Django's template engine can accept it. The key 'results' is more consistent with DRF's paginated response convention than 'details'. Fixes encode#5236
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5236
Problem
TemplateHTMLRenderer.get_template_context()wraps list data (from list views andValidationError) in a dict using'details'as the key. This was introduced in #9467.The key
'details'is inconsistent with DRF's own paginated response convention which uses'results'. Maintainer @lovelydinosaur explicitly requested'results'in the issue thread, and contributor @auvipy agreed in PR #8569.Change
One-line rename:
'details'→'results'inget_template_context().Templates using
TemplateHTMLRendereron a list view should reference{{ results }}or iterate with{% for item in results %}.Tests
test_list_view_with_template_html_renderer: end-to-end test of a list view rendered viaTemplateHTMLRendererusing{{ results }}test_get_template_context_wraps_list_under_results_key: unit test that asserts the context dict uses'results'and not'details'Migration note
Projects that upgraded after July 2024 (when #9467 landed) and are using
{{ details }}in their templates will need to rename the variable to{{ results }}.