Learning Jinja2: Part 1: Installing and Using

Learning Jinja2

Jinja2 is a template engine for Python featuring an optional sandbox environment.


Installing

Jinja2 is one of many packages available via PIP.

pip install jinja2

Note: Some environments and platforms like Heroku have different installation methods for packages. Consult the documentation of web services and online platforms for their instructions.

Using

Once installed, Jinja2 can accessed through the normal package methods of the using the fromimport.

The Template() function loads some texts that contains text containing symbols to be changed during rendering. Once created, the render() function converts (interpolates) text based on variable and other names into their values.

Play with the example on Repl.it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.