Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8106083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:21:10+00:00 2026-06-06T00:21:10+00:00

Is there a lower-level way to provide the list of loaders when rendering a

  • 0

Is there a lower-level way to provide the list of loaders when rendering a template, as opposed to always having Django use the setting?

I’d like to use a custom template loader instance for only a few views (I have my reasons).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:21:14+00:00Added an answer on June 6, 2026 at 12:21 am

    It looks like you’ll have to write some code of your own to do it. Let’s take a look at the normal code path for loading templates, if you use, say, render_to_response, where the relevant part of the source is:

    return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
    

    That’s a call to django.template.loader.render_to_string, which passes through some other functions and eventually ends up calling find_template.

    The first time find_template is called, in initializes the global template_source_loaders cache based on settings.TEMPLATE_LOADERS. So it looks like there’s no just extra argument you can pass in or anything like that.

    One possibility might be to add some loaders to django.template.loader.template_source_loaders just for the duration of that view. I don’t know if that will cause other problems; it feels dirty, but if it works, it’ll be pretty easy. (Just make a view decorator that does it.)

    If you don’t want to do that, it looks like you’ll have to replicate the work of render_to_string with your own code (if you’re really sure you want to use per-view template loaders, which I’m accepting as a premise for the sake of this question but I bet isn’t actually necessary). There’s not all that much code there, and if you know in advance a specific loader and a single template name that you want to use, it’s actually pretty easy. (This is untested but will probably pretty much work.)

     def render_to_response_with_loader(loader, name,
               dictionary=None, context_instance=None, mimetype=None, dirs=None):
    
        # from find_template
        t, display_name = loader(name, dirs)
    
        # from get_template
        if not hasattr(t, 'render'):
            # template needs to be compiled
            t = django.template.loader.get_template_from_string(t, origin, template_name)
    
        # from render_to_string
        if not context_instance:
            rendered = t.render(Context(dictionary))
        else:
            # Add the dictionary to the context stack, ensuring it gets removed again
            # to keep the context_instance in the same state it started in.
            context_instance.update(dictionary)
            try:
                rendered = t.render(context_instance)
            finally:
                context_instance.pop()
    
         # from render_to_response
         return HttpResponse(rendered, mimetype=mimetype)
    

    If you want to support multiple possible loaders or a list of possible filenames, just copy the relevant code from django.template.loader.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a defined way of downgrading a solution to a lower version of
I am curious if there is a way where I can capture the lower
Are there pybluez wrapper functions for lower level bt functionality? I couldn't find anything
Program design: Class A, which implements lower level data handling Classes B-E, which provide
I am wondering if there is a way to use the simpler classes in
There have been proposals for C++ delegates which have lower overhead than boost::function :
There's a Rails 3.2.3 web application which doesn't use any database. But in spite
There is a directed graph having a single designated node called root from which
Is there a way I can configure the AdoNetAppender to log every time a
On Linux, for a C/C++ program using pthreads, is there a way to see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.