render_template with multiple variables

You can pass multiple parameters to the view.

You can pass all your local variable

@app.route('/')
def index():
  content = """
     teste
   """
  user = "Hero"
  return render_template('index.html', **locals())

or just pass your data

def index() :
    return render_template('index.html', obj = "object", data = "a223jsd" );

api doc


return render_template('im.html', user= None, content = xxx, timestamp = xxx)

You can pass as many variables as you need. The api

excerpt:

flask.render_template(template_name_or_list, **context) Renders a template from the template folder with the given context.

Parameters: template_name_or_list – the name of the template to be rendered, or an iterable with template names the first one existing will be rendered context – the variables that should be available in the context of the template.


It is also possible to pass a list to render_template's context variables, and refer to its elements with Jinja's syntax in HTML.

example.py

mylist = [user, content, timestamp]
return render_template('exemple.html', mylist=l)

exemple.html

...
<body>
    {% for e in mylist %}
        {{e}}
    {% endfor %}
</body>
...