# Jinja (Django) templates

Jinja templates in services - rendering HTML and other frontend output from Python code.

- [Jinja](https://jinja.palletsprojects.com/en/3.1.x/) is a templating language that Zato services can use to output HTML or other static resources typically needed by [backend dashboards](https://zato.io/docs/dev/frontend/index.html) and other frontend applications.

- For instance, a Zato service could accept input from frontend, connect to multiple backend systems to obtain the required data and then return a HTML with all the information ready for the frontend to display.

- Note that Jinja is sufficiently similar to the templates that Django uses and if you know the latter, using Jinja will come naturally.

- Zato already ships with Jinja and there is no need to install it separately.

## Outputting HTML {#outputting-html}

Here is a sample frontend service that returns an HTML list representing clients. For simplicity, the actual information is returned directly from the "get\_data" function but a real service could look it up in an external data store. Regardless of where the data comes from, the usage of Jinja is the same.

```python
# -*- coding: utf-8 -*-

# Jinja
from jinja2 import Template

# Zato
from zato.server.service import Service

# ########################################################################################
# ########################################################################################

template = Template("""
    <ol>
        {% for item in items %}
            <li>{{ item }}</li>
        {% endfor %}
    </ol>
""")

# ########################################################################################
# ########################################################################################

class FrontedJinja(Service):

    name = 'api.frontend.jinja'

    def get_data(self):

        return [
            'Jane Doe',
            'John Brown',
            'Jackie Smith',
        ]

    def handle(self) -> 'None':

        # Obtain our data to produce the HTML for
        data = self.get_data()

        # A dictionary with configuration for the template
        config = {
            'items': data
        }

        # Generate HTML
        html = template.render(**config)

        # Assign HTML payload to the response
        self.response.payload = html

        # Set the output Content-Type as well
        self.response.headers['Content-Type'] = 'text/html'

# ########################################################################################
# ########################################################################################
```

The service will produce the following:

```html
<ol>
    <li>Jane Doe</li>
    <li>John Brown</li>
    <li>Jackie Smith</li>
</ol>
```

Note that Jinja can be used to output other formats as well, e.g. CSV or any other information that will be easier to output with a templating language instead of constructing the responses manually.

## Learn more {#learn-more}

- [Development documentation](https://zato.io/docs/dev/) - The complete reference for writing services
- [Requests and responses](https://zato.io/docs/dev/request-response/) - What a service receives, what it returns and how both are structured
- [Integration examples](https://zato.io/docs/dev/examples/) - Ready-made code for the systems you are likely to connect to
- [IDE and debugging](https://zato.io/docs/dev/ide/) - Write services in the Dashboard or in your own editor
- [Data models](https://zato.io/docs/dev/model/) - Declare inputs and outputs and have them validated for you
- [In-depth API tutorial](https://zato.io/tutorials/main/01.html) - The full platform tutorial, from installation to production patterns
