Tasos
Tasos

Reputation: 7587

Use templates in Python Bottle

Currently, I use Python Bottle in one of my projects. I want to change it and use templates like Jinja2 tutorials with extends and includes to avoid repeating navbars, footers etc.

In Jinja2 I could use something like this:

{% extends base.html %}

{% block maincontent %}
<here my HTML code>
{% endblock %}

I found that I can use this with Bottle by importing Jinja2 view and template, but then I have to reformat every Python code in HTML pages from Bottle to Jinja2 formats.

For example:

from:

%for i in mylist:
<option>{{i}}</option>
%end

to:

{% for i in mylist %}
<option>{{i}}</option>
{% endfor %}

Is there any way to use extends with Bottle template without changing all my Python code? I cannot find any tutorial.

Upvotes: 1

Views: 2580

Answers (1)

loopbackbee
loopbackbee

Reputation: 23342

The template engine bottle uses, SimpleTemplate, doesn't support inheritance. You can, however, use include to separate things like headers and footers, or rebase to simulate inheritance.

Of course, since SimpleTemplate is, well, simple, if you know you'll need more advanced templating features, it'll be less costly to migrate now rather than later.

Upvotes: 2

Related Questions