Andrea
Andrea

Reputation: 87

Best way to recursively include python Tornado templates

I've in my python project, using the tornado library:

1) A main html template (the web page structure), like:

base.html:

 <html>
 <head>....</head>
 <style>...</style>

 <div id="content">
 {{ sub_template_content }}
 </div>
</html>

2) multiple sub-templates, one for each page, like:

page1.html:

<b>page 1 {{ content }}</b>

page2.html:

<b>page 2 {{ content }}</b>

The idea is to always build the page using the "base" template and then include the "sub-template" dynamically (based on the get parameter).

So, what's the best way to do that? I already tried using the tornado "include" function, but without success. Thanks!

Upvotes: 0

Views: 1033

Answers (1)

Ben Darnell
Ben Darnell

Reputation: 22134

Use the extends/block feature instead. In base.html:

<div id="content">
    {% block content %}{% end %}
</div>

In page1.html:

{% extends "base.html" %}
{% block content %}
    page 1 {{ content }}
{% end %}

Upvotes: 2

Related Questions