问题描述:

I'm developing a web portal using

- Django 1.2

- Apache

- Mod WSGI

I've several HTML files which are being served by apache.

I want to render those static HTML pages under my base template in order to keep my header / footer and dynamic menus intact.

One way I could thought its using iframes. Another way is to do read HTML files and return string while rendering but in that case I'm loosing advantage of apache, so I want to know if there would be any better way of doing it, is there any existing solution provided by django stuff ?

网友答案:

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' %}
网友答案:

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)

网友答案:

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/

相关阅读:
Top