I
I
Ilya2017-02-21 21:57:31
Python
Ilya, 2017-02-21 21:57:31

How to display a dictionary in Jinja2?

I'm trying to output the collected dictionary to the Jinja template, but it doesn't work.
the dictionary contains {'nginx': 'running', 'mysql': 'not running'}

@asyncio.coroutine
def handle(request):
    context = {}
    for daemon in service:
        status = subprocess.call('service %s status' %daemon,
                        shell=True,
                        stdout=open('/dev/null', 'w'),
                        stderr=subprocess.STDOUT
                        )
        tt = {daemon: commands[status]}
        context.update(tt)

    return aiohttp_jinja2.render_template('index.html', request, context)

Tried in different ways.
{{ context.items() }}
Mistake
jinja2.exceptions.UndefinedError: 'context' is undefined

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question