from django.template import Template template = Template("Hello, {{ name }}!") context = {"name": "World"} result = template.render(context) print(result) # output: "Hello, World!"
from django.template import Template, Context base_template = Template("""In this example, we are using template inheritance to create a child template that extends a base template. The child template overrides the title block to set a different title and the content block to include a greeting message. The django.template Template class and other similar classes in the django.template package are essential for building dynamic and flexible web applications using the Django framework.{% block title %}{% endblock %} {% block content %}{% endblock %} """) child_template = Template(""" {% extends "base_template.html" %} {% block title %}Child Template{% endblock %} {% block content %}Hello, World!
{% endblock %} """) context = Context() output = child_template.render(context)