Re: Specifying Django Project/Application Templates
If I understand your problem correctly, you can already override such
templates. If there is a template in your project's template directory
with the same name and sub-path as that used by django base code
or a system wide installed application, it will be used instead.
Perhaps an example. Suppose that you're using the foo application,
and it loads a template 'foo/bar.html', which is in the application's
'templates/foo' directory. This is found via the app template loader.
If you create a directory 'foo' as a subdirectory of your project's
'templates' directory, and put a file in it named 'bar.html', that will
be used instead of the one provided by the app.
The necessary (and common) pre-conditions for this to work are,
all in settings.py:
The full path to your templates directory is listed (probably first)
in the TEMPLATE_DIRS tuple. (I use os.path.join(PROJECT_ROOT,
"templates") which requires that I have earlier said something like
PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__)) .)
'django.template.loaders.filesystem.load_template_source' must
be listed in the TEMPLATE_LOADERS tuple, and come before
'django.template.loaders.app_directories.load_template_source'.
(These are usually the only two, and they are in that order by
default.)
Now, if you want to change what template the app's view tries to load,
so that you can still access the original to extend it, without copying
and renaming it, that's a more interesting problem.
Bill
On Thu, Oct 29, 2009 at 8:44 AM, Johan <djjordaan@gmail.com> wrote:
>
> Hi. Is there a way to specify custom project (or what I call sites)
> and application templates. At present the python-admin.py startproject/
> startapp uses the default templates that ships with django. I end up
> either having to create these myself or heavily modify them for my dev
> structure. It seems to me that it would be quite simple to change the
> code in django.core.management.base and
> django.core.management.commands.startproject/startapp to allow the
> user to specify custom project and application templates. The idea
> would be that i can run the following type of command: djang-admin.py
> startproject template.config. Does anybody see the need for this type
> of functionality or not?
> >
>
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home