Hi Jo,
You can return a string (e.g. a rendered jinja2 template) from the .render method of an IResource
So when you see a string being returned from a Resource in the docs, you can consider substituting the particulars of the template engine you want to use.
Here's a very simple example of one approach using jinja2:
## myapp/config.py
#
# Define a jinja2 Environment somewhere
# I specify a PackageLoader to look up templates from the templates folder in the myapp.web.static package
from jinja2 import Environment, PackageLoader
jinja = Environment(loader=PackageLoader('myapp.web.static', 'templates'))
----
## myapp/web/views.py
#
from twisted.web.resource import Resource
from myapp.config import jinja
class MyResource(Resource):
isLeaf = True
template_name = "example.html"
def render_GET(self, request):
ctx = {
'content': "Templated content",
'extra_info': [1, 2, 3, 4, 5, 6]
}
template = jinja.get_template(self.template_name)
return template.render(ctx)