Thursday, June 28, 2012

Re: Avoiding code repetition in views

On Jun 29, 2012, at 12:20 AM, grimmus wrote:

> I am doing a site for a DJ that lists upcoming gigs on each page. There's an include file in each page template to output the list of gigs.
>
> I am wondering how i can pass the gig information to every page without having to repeat the code in every page view.
>
> I hope i have been clear

I'm going to take a guess and surmise that you have a lot of different view functions, each one of which needs to pass a list of gigs into the context for the template and then render that page, and you're trying to avoid repeating the code that builds the list of gigs. Is that correct?

You might look at whether you really need all those separate view functions, or if they can be rolled together. You might also look at using class-based Views in 1.4 as a way to factor out the gig-list-building code in a reasonable way.

--
-- Christophe Pettus
xof@thebuild.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment