Re: template loading and generic views

2007-10-21 Thread Malcolm Tredinnick

On Sat, 2007-10-20 at 22:40 -0700, Leo Shklovskii wrote:
> Does anyone have any thoughts on this? is there a recommended way to lay 
> out the templates on a per-application basis? does it make sense to 
> change either of the two defaults to be consistent with each other?
> 
> --
> --Leo
> 
> Leo Shklovskii wrote:
> > I've got a question about the templates that the generic views load.
> > 
> > I have a app (named 'foo' in this example) that has its templates in a 
> > templates folder to work with 
> > django.template.loaders.app_directories.load_template_source.
> > 
> > so:
> > foo/templates/bar.html
> > foo/templates/bar_list.html
> > 
> > However, trying to use the generic view 
> > django.views.generic.list_detail.object_list and by default, it looks 
> > for a template named 'foo/bar_list.html' by default, but that doesn't 
> > exist. I can move the templates into:
> > 
> > foo/templates/foo/bar.html
> > foo/templates/foo/bar_list.html
> > 
> > But it seems a little silly to repeat 'foo' twice, and breaks being able 
> > to use just the template name 'bar.html' in other parts of django.
> > Alternatively I can specify the template name to object_list, but its so 
> > nice to pick convention over configuration :-)

You can't have it both ways. Either you use the default name (which is
app_label/model_name and, hence, specific to the app) or you specify the
name if you want to re-use the same name. It's only a single parameter
you have to write out. (option three is "don't use that particular
template loader for this case" -- see below).

> > Am I just setting up my project incorrectly? Or is there a better 
> > suggestion for how to deal with this situation?

The meta-issue here is the template loader you are using (the
app_directories one). This is a handy little loader for many cases, but
can lead to some redundancies. The problem is that it takes all
template/ directories inside all app directories and treats them as
equal and belonging to the top-level. So if you have

app_one/templates/foo.html
app_two/templates/foo.html

this is very bad if you are also using the app_directories loader. It
effectively merges the contents of app_one/templates/ and
app_two/templates/ together, so it's not well defined which foo.html you
end up loading when say give specify "foo.html" for this particular
loader.

The solution is either to always use unique template names (difficult if
you are using third-party apps) or get in the habit of constructing your
directories as 

app_one/templates/app_one/

(include the redundant app name) or don't use the app_directories
template loader (comment it out, even). Both of the latter two
possibilities are common (remember to configure TEMPLATE_DIRS if you are
using the filesystem loader only).

Notice, also, that template loaders are used from first to last, so you
can have some templates found automtically with the app_directories
loader and others found, by preference, using the filesystem loader and
TEMPLATE_DIRS. At the moment, I would guess you haven't set up any
tempate directories or put anything in TEMPLATE_DIRS, so the filesystem
loader isn't doing anything. But it is being run (first), unless you
have commented it out.

Regards,
Malcolm

-- 
The sooner you fall behind, the more time you'll have to catch up. 
http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template loading and generic views

2007-10-21 Thread Hugh Bien
foo/templates/foo/bar.html
foo/templates/foo/bar_list.html

This is the way I've been doing it (app/templates/app/model.html).  It works
well when you want to re-use your apps to make sure template names don't
conflict with other apps.

On 10/20/07, Leo Shklovskii <[EMAIL PROTECTED]> wrote:
>
>
> Does anyone have any thoughts on this? is there a recommended way to lay
> out the templates on a per-application basis? does it make sense to
> change either of the two defaults to be consistent with each other?
>
> --
> --Leo
>
> Leo Shklovskii wrote:
> > I've got a question about the templates that the generic views load.
> >
> > I have a app (named 'foo' in this example) that has its templates in a
> > templates folder to work with
> > django.template.loaders.app_directories.load_template_source.
> >
> > so:
> > foo/templates/bar.html
> > foo/templates/bar_list.html
> >
> > However, trying to use the generic view
> > django.views.generic.list_detail.object_list and by default, it looks
> > for a template named 'foo/bar_list.html' by default, but that doesn't
> > exist. I can move the templates into:
> >
> > foo/templates/foo/bar.html
> > foo/templates/foo/bar_list.html
> >
> > But it seems a little silly to repeat 'foo' twice, and breaks being able
> > to use just the template name 'bar.html' in other parts of django.
> > Alternatively I can specify the template name to object_list, but its so
> > nice to pick convention over configuration :-)
> >
> > Am I just setting up my project incorrectly? Or is there a better
> > suggestion for how to deal with this situation?
> >
> > --
> > --Leo
> >
> > >
> >
>
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template loading and generic views

2007-10-20 Thread Leo Shklovskii

Does anyone have any thoughts on this? is there a recommended way to lay 
out the templates on a per-application basis? does it make sense to 
change either of the two defaults to be consistent with each other?

--
--Leo

Leo Shklovskii wrote:
> I've got a question about the templates that the generic views load.
> 
> I have a app (named 'foo' in this example) that has its templates in a 
> templates folder to work with 
> django.template.loaders.app_directories.load_template_source.
> 
> so:
> foo/templates/bar.html
> foo/templates/bar_list.html
> 
> However, trying to use the generic view 
> django.views.generic.list_detail.object_list and by default, it looks 
> for a template named 'foo/bar_list.html' by default, but that doesn't 
> exist. I can move the templates into:
> 
> foo/templates/foo/bar.html
> foo/templates/foo/bar_list.html
> 
> But it seems a little silly to repeat 'foo' twice, and breaks being able 
> to use just the template name 'bar.html' in other parts of django.
> Alternatively I can specify the template name to object_list, but its so 
> nice to pick convention over configuration :-)
> 
> Am I just setting up my project incorrectly? Or is there a better 
> suggestion for how to deal with this situation?
> 
> --
> --Leo
> 
> > 
> 

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



template loading and generic views

2007-10-11 Thread Leo Shklovskii

I've got a question about the templates that the generic views load.

I have a app (named 'foo' in this example) that has its templates in a 
templates folder to work with 
django.template.loaders.app_directories.load_template_source.

so:
foo/templates/bar.html
foo/templates/bar_list.html

However, trying to use the generic view 
django.views.generic.list_detail.object_list and by default, it looks 
for a template named 'foo/bar_list.html' by default, but that doesn't 
exist. I can move the templates into:

foo/templates/foo/bar.html
foo/templates/foo/bar_list.html

But it seems a little silly to repeat 'foo' twice, and breaks being able 
to use just the template name 'bar.html' in other parts of django.
Alternatively I can specify the template name to object_list, but its so 
nice to pick convention over configuration :-)

Am I just setting up my project incorrectly? Or is there a better 
suggestion for how to deal with this situation?

--
--Leo

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---