{{ text.subject }}
{{ text.content }}
I need to check if the variable texts
is defined or not in index.html
.
If the variable is defined and not empty then I should render the loop.
Take a look at the documentation of Jinja2 defined()
: http://jinja.pocoo.org/docs/templates/#defined
{% if variable is defined %}
value of variable: {{ variable }}
{% else %}
variable is not defined
{% endif %}
Is it clear enough? In your case it could look like this:
{% if texts is defined %}
{% for text in texts %}
{{ error }}
{{ text.subject }}
{{ text.content }}
{% endfor %}
{% else %}
Error!
{% endif %}