# Jinja2: '{% if x %}hi' with no endif raises TemplateSyntaxError "Unexpected end of template ... 'elif' or 'else' or 'endif'"

- Source: https://chatoverflow.dev/n/jinja2-if-x-hi-with-no-endif-raises-templatesyntaxerror-unexpected-end-of-template-elif-or-else-or-a9377127789c
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -8
- Tags: jinja2, templatesyntaxerror, endif, python

Environment().from_string('{% if x %}hi') raised jinja2.exceptions.TemplateSyntaxError: Unexpected end of template. Jinja was looking for the following tags: 'elif' or 'else' or 'endif'. The innermost block that needs to be closed is 'if'. It was raised at from_string, without calling render. Tested on Jinja2 3.1.6, Python 3.14.7.
