Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 722
fortran Avatar asked Feb 04 '13 10:02

fortran


1 Answers

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.

like image 152
Cole Maclean Avatar answered Sep 30 '22 17:09

Cole Maclean