Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TemplateHTMLRenderer: assign the view to the template context #4230

Closed
rfleschenberg opened this issue Jun 29, 2016 · 1 comment
Closed

TemplateHTMLRenderer: assign the view to the template context #4230

rfleschenberg opened this issue Jun 29, 2016 · 1 comment

Comments

@rfleschenberg
Copy link
Contributor

Django's TemplateView assigns the view object to the template context. Some applications and libraries rely on this fact to provide useful functionality (in my case, django-parler's get_translated_url template tag).

DRF's TemplateHTMLRenderer does not do this, and as far as I see, it does not provide a hook to pass extra context to the template from the view.

  1. I propose to assign the view to the template context in TemplateHTMLRenderer.render(). This seems to be a trivial change: the view is already in the local scope via the renderer context.
  2. In addition, do you think it would be a good idea to provide a way to pass extra context to the template when using TemplateHTMLRenderer?
@tomchristie
Copy link
Member

Considered this, nearly accepted, then argued myself out of it.

I'm not too keen on presenting view in the context, as I believe that more constrained behavior of pulling in exactly what is needed and no more is more manageable, maintainable, and that we should direct users down that path in their own interests.

Answer to both (1) & (2) is this: If you need different context (or different behavior) then I'd suggest overriding TemplateHTMLRenderer.

Appreciate you raising the ticket and talking this though - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants