I’ m trying to build a Django TemplateLoader, but I can’t make it ‘see’ either the current Context or Request, so I can’t really do much with it.
Does anyone know how I can make a Django TemplateLoader do this?
Many Thanks
Joe
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The place to make decisions about templates is in your view. There, you have access to the request, and can dynamically construct a template name depending on whatever conditions you like. E.g.,
Where you provide the
is_mobile(). Better would be to provide a method that takes a request and template name, and returns one appropriately modified (so that you can encode that logic once, rather than scattering across several views).You might also get some leverage from select_template(), which takes a list of candidate template names, returning a template for the first one it finds.