[Django]-Render static html page inside my base django template

7đź‘Ť

I’m not sure if this is exactly what you’re asking for, but you can insert an html file (or even another template) in a template with the ssi and include tags, depending on your needs:

{% ssi '/path/to/file.html' %}
{% include 'relative/path/to/template.html' %}

2đź‘Ť

yes, it’s the include tag

Loads a template and renders it with the current context. This is a way of “including” other templates within a template.

it’s as simple as

{% include "templates/static_template_1.html" %}

or, if you create a variable in the view side:

{% include template_name_variable %}

it shares the context with the base template (the one including them)

2đź‘Ť

Edit:

Perhaps you ment to load html-files outside the template-system. Then my way will not suffice.

An option is to extend your base template.

Your base template should not be aware of the sub templates as that would be logically wrong.

Example:

base_template.html:

<html>
<div id='header'></div>
{% block content %}
    This text can be left out else it it will shown when nothing is loaded here
{% endblock %}

sub_template.html:

{% extends "base_template.html" %}

{% block content %}
    <h1>This is my subpage</h1>
{% endblock %}

You can read more here:

https://docs.djangoproject.com/en/1.2/topics/templates/

Leave a comment