#28331: extra_context argument on TemplateView.as_view
-------------------------------+--------------------------------------
     Reporter:  Jeremy         |                    Owner:  nobody
         Type:  Uncategorized  |                   Status:  new
    Component:  Uncategorized  |                  Version:  1.11
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------
Description changed by Jeremy:

Old description:

> It used to be possible to pass extra_context to direct_to_template.  Then
> direct_to_template was replaced with TemplateView.as_view ... but the
> latter function never got the ability to take an extra_context arg.
>
> As a result there are now half a trillion (rough estimate) re-
> implementations of the following:
>

> {{{
> class StaticPageView(TemplateView):
>     context = None
>
>     def get_context_data(self, **kwargs):
>         context = super(StaticPageView, self).get_context_data(**kwargs)
>         context.update(self.context or {})
>         return context
>

> }}}
> You can find them across the web, across StackOverflow, etc.  Everyone
> has to remake this one small class just so that they can pass an extra
> context to template-only views.
>
> This is counter-productive: the whole point of a framework is to
> *prevent* everyone from having to re-invent the same code.  Adding yet
> another re-implementation of StaticPageView does nothing to improve the
> code, it only clutters it up with boilerplate.
>
> Please fix this by allowing as_view (ideally in all generic views) to
> take an extra_context arg.

New description:

 It used to be possible to pass extra_context to direct_to_template.  Then
 direct_to_template was replaced with TemplateView.as_view ... but the
 latter function never got the ability to take an extra_context arg.

 As a result there are now many many re-implementations of some variation
 of the following:


 {{{
 class StaticPageView(TemplateView):
     context = None

     def get_context_data(self, **kwargs):
         context = super(StaticPageView, self).get_context_data(**kwargs)
         context.update(self.context or {})
         return context


 }}}
 You can find them across the web, across StackOverflow, etc.  Everyone has
 to remake this one small class just so that they can pass an extra context
 to template-only views.

 This is counter-productive: the whole point of a framework is to *prevent*
 everyone from having to re-invent the same code.  Adding yet another re-
 implementation of StaticPageView does nothing to improve the code, it only
 clutters it up with boilerplate.

 Please fix this by allowing as_view (ideally in all generic views) to take
 an extra_context arg.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28331#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/070.ce80c12b8ab75a78977e1f3fe44f5929%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to