[Answered ]-Django view/template redirection for mobile browsers

2👍

Dynamically modifying the template search path is a great way to handle this. It’s not hard to define your own template loader and add it to the TEMPLATE_LOADERS in settings.py. The tricky part of this is handling the fact you may be running in a multi-threaded environment, and you don’t have a way to pass your request directly to the template loader.

The way around it is to store the request, a flag, or simply the directories to add to the path in a thread local variable, and reference that thread local variable from a custom template loader. Here’s a blog post about creating template loaders, I can vouch for the fact it’s pretty easy and works. Here’s an even better one about doing exactly what you need.

I guess i didn’t specifically point out that you probably do not want to try to change settings.TEMPLATE_DIRS per request, you will get wierd results at best.

👤easel

Leave a comment