On Tue, Jan 10, 2012 at 6:13 PM, IgorS <igor.shm...@gmail.com> wrote: > First of all, thanks a lot to everyone who replied :-) > > Tom: > > As i mentioned, i am new to Django and could be missing big parts. > Please do not hate me too much for my naivete :-)
Never apologise for trying to learn :) It took me a really long time to get to grips with how apps should interact with projects. You've avoided many of the problems I encounter with my production sites :) > But I have some doubts regarding the templates. And the doubts come > exactly from that [explicit vs. implicit] perspective. Why not making > it more explicit? I mean to change it in a way that there is no need > to relay on the order in which Django searches for the templates. The > order is defined at the project level and this unnecessarily couples > my application with the project. Python programming tends to have at least two golden rules*: 1) Explicit is better than implicit 2) Don't repeat yourself Sometimes I feel that that these two rules are at odds with each other, and this would be one of those cases. It would be more explicit to manually resolve the template that you want in the view, but then we would have to manually resolve which template in every view :) So instead, the best way is to explicitly include the app name in the template name, by keeping templates in a subdirectory named after the app, and allow simple template loaders to find it. This actually reduces coupling, as another poster has alluded to, as you can override a specific app's template on the project level. As an example, when using django's admin app, you can override specific templates by creating the appropriately named template in your project template directory: https://docs.djangoproject.com/en/1.3/ref/contrib/admin/#overriding-admin-templates If the view manually resolved the template to use, you would need to provide a mechanism to allow a project to override an app template. Remember that the app author is not necessarily the project author. > The only two places where the templates are referenced are the views > and other templates (in the “extends” tag). Please correct me if I am > wrong. Well, technically templates can be used for generating any textual content, for instance I use templates to generate email contents in backend (non website driven) processes. But yes, pretty much - and the use is pretty much the same (render_to_string() rather than render_to_response() or render()). [...] > Am I digging in a wrong direction? Is it easier to just rely on the > Django's template scanning order and to forget the whole thing? > What do you think? Yep, I think that the current 'standard' of prefixing your templates with your app name is pretty good. There are no major flaws in how it currently operates, and it offers a lot of flexibility. Cheers Tom * I always add this rule to any golden rules: 3) You don't always have to obey golden rules! -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.