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 8837607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:46:11+00:00 2026-06-14T09:46:11+00:00

I am working on a project where some templates are stored as part of

  • 0

I am working on a project where some templates are stored as part of a ‘theme’ in the database. Because of this, I’m not able to leverage a lot of Django’s nice template rendering functionality immediately. For example:

# Instead of this...
return render_to_response('path/to/template', arguments, context_instance=context)

# Have to do this...
template = Template(model.template_field)
context.update(arguments)
return HttpResponse(template.render(context))

This is fine, however, the problem that I’ve run in to is including sub-templates. If, for example, model.template_field looks like this…

<html>
    <head>
        {% include head_extra %} <!-- Another DB field -->
    </head>
    <body>
        {% include body_extra %} <!-- Another DB field -->
    </body>
 </html>

…Then Django will complain that the template doesn’t exist (because there is no template with that name).

How can I include the sub-templates in a dynamically created template?

Edit (Ignoring the database constraint, and providing more details):
I want users to be able to define their own templates, either via a file upload, or through some editor.

I would like them to be able to include sub-templates via {% include %}, but I don’t want the user to have to worry about where they are including from. Hence, I just want them to include like this: {% include extra_head %}. However, django certainly needs to know where the templates are located in order to load them.

What do people typically do when they want user defined templates in django?

  • 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-14T09:46:12+00:00Added an answer on June 14, 2026 at 9:46 am

    If you are willing to waive the requirement that {% include %} statements are needed, you can do things by hand if you try something like this in your view…

    def view(request, id):
        theme = get_object_or_404(Theme, pk=id)
        original_context = RequestContext(request)
    
        page_context = Context({
            'db_head': Template(theme.head_template).render(original_context),
            'db_body': Template(theme.body_template).render(original_context)
        }
    
        page = Template(theme.page_template)
        return HttpResponse(page.render(page_context))
    

    …With a ‘template’ like this:

    <html>
        <head>
            {{ db_head }}
        </head>
        <body>
            {{ db_body }}
        </body>
    </html>
    

    This pattern can work for more deeply nested elements as well provided you build the lowest level templates first. You can include existing templates via render_to_string, but you can still run into problems if you ever want to include something within a loop context.

    A bit kludgy, and not exactly what you’re looking for, but it will work.

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

Sidebar

Related Questions

I am working on a django- Google app engine project. A user inserts some
I am working on a project which will include automatically filling out some templates.
I'm working on a django project that's not mine, but trying to add a
I'm working on a project and I want to be able to handle some
I am working on some project that needs that when ever a friend of
I'm working on a project involving some large XML files (from 50MB to over
I'm currently working on a project with some fancybox (inline content). I'd like to
I'm working on project that lets users choose some scientific authors and columnists and
I'm working on a project which includes some slightly more complex dynamic layout of
I am working on a project that requires some image processing. The front end

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.