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

  • SEARCH
  • Home
  • 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 4568046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:01:13+00:00 2026-05-21T19:01:13+00:00

In django I have a view that fills in a template html file but

  • 0

In django I have a view that fills in a template html file but inside the html template I want to include another view that uses a different html template like so:

{% block content %}
Hey {{stuff}} {{stuff2}}!

{{ view.that_other_function }}

{% endblock content %}

Is this possible?

  • 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-05-21T19:01:14+00:00Added an answer on May 21, 2026 at 7:01 pm

    Yes, you need to use a template tag to do that. If all you need to do is render another template, you can use an inclusion tag, or possibly just the built in {% include ‘path/to/template.html’ %}

    Template tags can do anything you can do in Python.

    https://docs.djangoproject.com/en/3.0/howto/custom-template-tags/

    [Followup]
    You can use the render_to_string method:

    from django.template.loader import render_to_string
    content = render_to_string(template_name, dictionary, context_instance)
    

    You’ll either need to resolve the request object from the context, or hand it in as an argument to your template tag if you need to leverage the context_instance.

    Followup Answer: Inclusion tag example

    Django expects template tags to live in a folder called ‘templatetags’ that is in an app module that is in your installed apps…

    /my_project/
        /my_app/
            __init__.py
            /templatetags/
                __init__.py
                my_tags.py
    
    #my_tags.py
    from django import template
    
    register = template.Library()
    
    @register.inclusion_tag('other_template.html')
    def say_hello(takes_context=True):
        return {'name' : 'John'}
    
    #other_template.html
    {% if request.user.is_anonymous %}
    {# Our inclusion tag accepts a context, which gives us access to the request #}
        <p>Hello, Guest.</p>
    {% else %}
        <p>Hello, {{ name }}.</p>
    {% endif %}
    
    #main_template.html
    {% load my_tags %}
    <p>Blah, blah, blah {% say_hello %}</p>
    

    The inclusion tag renders another template, like you need, but without having to call a view function. Hope that gets you going. The docs on inclusion tags are at: https://docs.djangoproject.com/en/3.0/howto/custom-template-tags/#inclusion-tags

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

Sidebar

Related Questions

I have a simple Django view that just returns URL parameters, but if I
I have a django project that uses views from an external app. The view
I have a django view that searches my database for a name that includes
I have a django view that returns HTTP 301 on a curl request: grapefruit:~
I have the view function in django that written like a dispatcher calling other
I have a django view generating a bunch of data which I want to
I have a Django view which reads a CSV file and saves it to
In my django app, I have a view which accomplishes file upload.The core snippet
I have a ModelForm that I have created a view and template with to
I have a Django view called change_priority. I'm posting a request to this view

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.