tags:

views:

46

answers:

1

When doing larger sites in "big business", you most probalbly work in a team with several developers.

Let's say dev A makes a form to insert new user data, B creates a user list, C makes some privilege administration and D does crazy statistic graphs work with image generation and so on.

Each dev begins to develop his own component, creates a view and a template and tests that independently, until each component works.

Now, the client wants to have all those components on one bit HTML page. How to achieve this? How to assemble different views/templates in a form of composition so that they remain modular and can be developed and tested independently?

It seems inheritance is not the way to go because all of those UI components are equal and there is no hierarchy.

The idea of the assembling template is something like

<html>
<head>
// include the css for the components and their assembly
</head>

<body>
// include user data form here
<some containers, images, and so on>
// show user list
// show privilege administration in this part
// and finally, the nice statistic graphs

// perhaps, we want to display some other components here in future
</body>
</html>

I have not found an answer on the net yet. Most people come up with one big template which just implements all of the UI functionality, removing all modularity. Each component shall have its own template and view dealing only with that component developed by one person each, and they then shall be sticked together just like bricks.

I would highly appreciate any hints!

+3  A: 

Inclusion tags are the way to do this. Each application defines tags which render their own template fragments, then the master template can assemble them into a single page.

Daniel Roseman
Seems to work fine, although I'm not sure the way I took is the most concise and necessary way, but I couldn't find detailed examples.
nh2
See this blog post from James Bennett - it's a bit outdated (it doesn't cover the shortcut decorators) but the principles are sound: http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/
Daniel Roseman
Thanks, that post is indeed very clear.However, would you recommend inclusion tags even for complex things like forms and so on? Most examples I've found deal with small things like 'show all books of this author' or just that 'get the latest NUM from X', but actually no example in which the thing included by the template tag had to deal with user input and the corresponding logic - it seems strange to me to do that in a template tag function instead of a view, but I'm only guessing.
nh2