[BangPypers] Writing extendable django views

Venkatraman S venkat83 at gmail.com
Wed Jul 6 16:51:31 CEST 2011


On Wed, Jul 6, 2011 at 7:45 PM, Amit Sethi <amit.pureenergy at gmail.com>wrote:

> Hi all , This is just a thought
>
> The question is very abstract , how do you write extendable django
> views . In particular while working on a certain problem . I realized
> that i was changing my views just to add certain context variables to
> the standard views provided by an external django app.
>
> I wonder generally people handle this:
>
> The standard view provided by the lib returns something like
>
> return render_to_response(template_name, {
>        "form": form,
>        "reply": reply,
>        "tweets": tweets,
>       }, context_instance=RequestContext(request)
>
>
> what I need is :
> return render_to_response(template_name, {
>        "form": form,
>        "reply": reply,
>        "tweets": tweets
>        "extra_context":extra_context,
>       }, context_instance=RequestContext(request)
>
> Note this is not some extra context I could have added through
> middleware or context processor . I just wish to increase the
> reusability of the view already written.
> Any ideas.
>
>
I am not sure whether i understood your Q right. The context is just a dict
- why not keep adding to it?
OR did you mean, changing the signature of views.py so that its extendable
and can take in variable number of args?
IF the latter, then prefer to use "*args, **kwargs" as the params across
*all* your views right from day-1.

Again, am sorry if i did not gather your q right. Can you expatiate?

-V


More information about the BangPypers mailing list