Template RenderingΒΆ

Template rendering of FutureFinity uses the Jinja2 Template Engine, but FutureFinity replaces the TemplateLoader to load template from filesystem asynchronously (it takes the advantage of multithreading).

Let’s look at the example below:

from futurefinity.template import render_template

import futurefinity.web

import asyncio

app = futurefinity.web.Application(template_path="./template/",

class MainHandler(futurefinity.web.RequestHandler):
    async def get(self, *args, **kwargs):
        username = self.get_secure_cookie("username", default=None)
        if not username:
            return self.redirect("/login")

        return self.render("main.htm", template_dict={"name": username})

class LoginHandler(futurefinity.web.RequestHandler):
    async def get(self, *args, **kwargs):

    async def post(self, *args, **kwargs):
        username = self.get_body_arg("username")
        self.set_secure_cookie("username", username)
        return self.redirect("/")


except KeyboardInterrupt:

The example presents that FutureFinity supports two ways to render template. One is RequestHandler.render classmethod, and the other one is futurefinity.template.render_template decorator.

For the information about the Jinja2 Template, please visit: Jinja2 Documentation

If you want to override the template engine, you can just override ReuqestHandler.render_string method to switch to other template engine.