Adrian wrote:

> Anybody care to tackle the separation of Django templates? The main
> thing is decoupling it from django.core.settings (and, hence,
> DJANGO_SETTINGS_MODULE), of which I'm not sure what the best
> approach would be.

a simple solution would be to use lazy loading of the settings
module in django.template, change all template code to access
the settings via django.template.settings, and let an external
user configure the template package *before* loading the first
template:

    from django import template

    template.config(TEMPLATE_DIRS=(...))

    t = template.loader(...)

where config does something like

    class Settings:
        TEMPLATE_DIRS = ()
        DEFAULT_CHARSET = "utf-8"
        ...

     def config(TEMPLATE_DIRS=(), **options):
         global settings
         new_settings = Settings()
         new_settings.TEMPLATE_DIRS = TEMPLATE_DIRS
         for k, v in options.items():
             if not hasattr(new_settings, k):
                 raise some exception
             setattr(new_settings, k, v)
         settings = new_settings

to implement the lazy loading, relevant template entry points
(loader, template constructors, etc) must do

     django.template.config_setup()

which does something like

     def config_setup():
         global settings
         if settings is None:
             from django.conf import settings
         return settings         

</F>

Reply via email to