django: generic views + custom template tags or custom views + generic/normal template tags -
this more of best-practices question, , given i'm quite tired mightn't make sense.
i've been putting blog app learning experience , actual part of website developing.
i've designed apps can list blog posts multiple criteria i.e.
/blog/categories/ /blog/authors/ /blog/tags/ /blog/popular/ etc.
on each page above want list how many entries part of criteria
i.e. "categories", want /blog/categories/ list different categories, mention how many blog posts in category, , possibly list entries.
django seems give lots of ways of doing this, not indication on what's best in terms of flexibility, reusability , security.
i've noticed can either
a: use generic/very light views, pass queryset template, , gather remaining necessary information using custom template tags.
i.e. pass queryset containing categories, , each category use template tag fetch entries category
or b: use custom/heavy views, pass 1 or more querysets + necessary information through view, , use less template tags fetch information.
i.e. pass list of dictionaries contains categories + entries.
the way see view there take in http requests, gather required information (specific what's been requested) , pass http request , context rendered. template tags should used fetch superflous information isn't particularly related current template, (i.e. latest entries in blog, or popular entries, can whatever like.)
this lack of definition (or ignorance on part) starting me, , i'd consistent in design , implementation, input welcome!
i'd understanding quite right. main method of gathering information , rendering via template view. template tags there information , processing might need do, perhaps across multiple views, not directly related view you're rendering.
you shouldn't worry making views generic. that's built-in generic views for, after all. once need start stepping outside provide, should make them specific use cases. might of course find common functionality used in multiple views, in case can factor out separate function or context processor, on whole view standalone bit of code particular specific use.
Comments
Post a Comment