fortran
fortran

Reputation: 76057

Can I include a template that extends another in Tornado?

I'm stumbling with an error when trying to do something as simple as including a template that extends another one... I'm not sure if that's an unsupported case or I'm doing something wrong, because it seems like a very common scenario.

The smallest code that I've managed to write to reproduce the error is this:

test.py

import tornado.template
loader = tornado.template.Loader(".")
templ = loader.load("t1.html")

t1.html

{% include "t2.html" %}

t2.html

{% extends "t3.html" %}

t3.html

{# empty #}

when running test.py I get a NotImplementedError raised in tornado's template.py

Am I missing something or is this a bug?

Upvotes: 7

Views: 3954

Answers (1)

Cole Maclean
Cole Maclean

Reputation: 5687

Ah, sorry, I got too focused on the missing blocks.

What you've described doesn't work using {% include %}, but works for me using {% module Template('t2.html', **args) %}, which will render the template in it's own namespace. Module setup is done automatically by tornado.web.Application, but not with the minimal template loader in your example.

This limitation seems to be there because of the way the {% extends %} tag is implemented.

Upvotes: 5

Related Questions