Robert Wittams wrote: > Sorry, I just can not work out what on earth you are actually trying to > achieve - too many instances of the word 'generic'... A concrete > example would be best.
Robert, Sorry, I guess I wasn't communicating very clearly. What I want is something like the {% include %} tag but with batteries included. With the {% include %} tag I still have to find some context from somewhere to render the included template - either it's provided by the main (custom) view or by custom template tags - I'd like to get it from something like a generic view - the less coding the better. An example: Suppose I make a very simple site to show details of people - I have a template to show name, date of birth etc. I want to visit e.g. http://localhost/people/1/ to see the first person's details, .../people/2/ to see the second etc., so I create a urlconf to connect urls of the form /people/(\d+)/ to an object_detail generic view and pass in a dictionary with app_label and module_name set appropriately. Suppose I make a very similar simple site for cars instead of people. So every page looks something like this in my people app: Name: Bob Jones Date of birth: 10/10/2010 or this in my car app: Manufacturer: Ford Model: Focus Color: Red Then I decide I would like to add, on each page, next to the detail of each person or car, a list of all people or all cars, so I can click on a person or car and it will take me to the detail page for that person or car (which still has the list next to the detail). So every page looks something like this in my people app: Bob Name: Bob Jones Mary Date of birth: 10/10/2010 John or this in my car app: Ford Focus Manufacturer: Ford Hummer H2 Model: Focus Fiat Panda Color: Red If I was to make a list of all cars or people as a separate page I could use an object_list generic view, but since I've already used an object_detail generic view for my page I can't use another view - each page has only one view. Obviously I could write a custom view, but I like generic views - what would be nice would be if I could make a page just for the list, using a generic view, configured with a url, and then include that page, rendered by its generic view, into my original page, just by including its url. That's what my template tag above does. In other words my {% include_url %} template tag is kind of like the {% include %} tag, but it doesn't take the path to a template, it takes the url of a page, and instead of being replaced by that un-rendered template (which is subsequently rendered with the context of the template it is included within), it is replaced by the rendered page. -- An alternative would be to write template tags equivalent to each generic view and use those along with an {% include %} tag. -- I think each solution has their pros and cons - my include_url tag requires that the pagelets (i.e. the pages showing just the lists) have their own urls - which doesn't seem right since nobody should ever really navigate to those urls (except perhaps for testing) - they're just used for including in the main page. On the other hand if I use some kind of new 'generic' template tags (i.e. template tag equivalents of generic views) then I have two choices: - I could add the 'generic' template tag to the *included* template - but then the included template has to hard code all the values to pass to the 'generic' template tag (such as the app_label and the module_name) and I can't re-use it. - I could add the 'generic' template tag to the *including* template, but then it pollutes the context. The generic template tag would have to return something like 'object' or 'object_list' so I couldn't add two in the same template. I'm still not sure which is the best way, or if there's another way I haven't thought of. I hope that's at least slightly clearer.