Loader Template without context (request), Use Case and Proposal

23 views
Skip to first unread message

aRkadeFR

unread,
Jun 6, 2016, 10:02:26 AM6/6/16
to django...@googlegroups.com

Hello all,

I'd like to open a discussion on the Loader Template (django/template/loaders/app_directories.py)
which is linked to the Template Engine (django/template/engine.py) about
the context it has when determining the templates to load.

## Use Case

In order to do multi-tenancy on our project, we set the current_site on
the input request in a middleware (almost the same as
django/contrib/sites/middleware.py).

Then our part of the system base its computation on the current_site of
the request.

Some of our clients needs to have specific markup template (.html
template).

In order to do that, we chose a hierarchy of templates, that can be
overriden if we have another folder with the same name of the
client/website.

Let's take an example:

We have as templates:
- /default/base.html
- /custom/base.html

If the request.site is named "custom", then we want to load the
/custom/base.html . Otherwise we load the /default/base.html


## Problem encounter

The Loader for the template doesn't have any context, and so we have
setup a global state with the request in threads local. I personnaly
hate global state in Django
(https://code.djangoproject.com/wiki/GlobalState).


## Proposal

I'd like to know if we could add the possibility to have more context on
the Loader? At least the request?

This is a bit of refacto in the code of Django as the Engine is created
only once for every Django process.


Thanks for your reading,

Have a good day

Tim Graham

unread,
Jun 6, 2016, 3:37:17 PM6/6/16
to Django users, con...@arkade.info
Doesn't seem too likely to me as all user-facing rendering functions would have to accept (require?) the request argument.

By the way, not sure if this post might have been meant for the django-developers mailing list?
Reply all
Reply to author
Forward
0 new messages