TemplateSyntaxError Invalid block tag: 'endif', expected 'endblock'

Raised by:

django/template/base.py (line 394)

Traceback (most recent call last):
  File "python2.7/site-packages/django/core/handlers/base.py", line 164, in get_response
    response = response.render()
  File "python2.7/site-packages/django/template/response.py", line 158, in render
    self.content = self.rendered_content
  File "python2.7/site-packages/django/template/response.py", line 133, in rendered_content
    template = self._resolve_template(self.template_name)
  File "python2.7/site-packages/django/template/response.py", line 88, in _resolve_template
    new_template = self.resolve_template(template)
  File "python2.7/site-packages/django/template/response.py", line 78, in resolve_template
    return loader.select_template(template, using=self.using)
  File "python2.7/site-packages/django/template/loader.py", line 64, in select_template
    return engine.get_template(template_name, dirs)
  File "python2.7/site-packages/django/template/backends/django.py", line 30, in get_template
    return Template(self.engine.get_template(template_name, dirs))
  File "python2.7/site-packages/django/template/engine.py", line 167, in get_template
    template, origin = self.find_template(template_name, dirs)
  File "python2.7/site-packages/django/template/engine.py", line 141, in find_template
    source, display_name = loader(name, dirs)
  File "python2.7/site-packages/django/template/loaders/base.py", line 13, in __call__
    return self.load_template(template_name, template_dirs)
  File "python2.7/site-packages/django/template/loaders/base.py", line 23, in load_template
    template = Template(source, origin, template_name, self.engine)
  File "python2.7/site-packages/django/template/base.py", line 190, in __init__
    self.nodelist = engine.compile_string(template_string, origin)
  File "python2.7/site-packages/django/template/engine.py", line 261, in compile_string
    return parser.parse()
  File "python2.7/site-packages/django/template/base.py", line 341, in parse
    compiled_result = compile_func(self, token)
  File "python2.7/site-packages/django/template/loader_tags.py", line 210, in do_extends
    nodelist = parser.parse()
  File "python2.7/site-packages/django/template/base.py", line 341, in parse
    compiled_result = compile_func(self, token)
  File "python2.7/site-packages/django/template/loader_tags.py", line 184, in do_block
    nodelist = parser.parse(('endblock',))
  File "python2.7/site-packages/django/template/base.py", line 339, in parse
    self.invalid_block_tag(token, command, parse_until)
  File "python2.7/site-packages/django/template/base.py", line 394, in invalid_block_tag
    (command, get_text_list(["'%s'" % p for p in parse_until])))
TemplateSyntaxError: Invalid block tag: 'endif', expected 'endblock'

How to reproduce

Add a syntax error to a Django template related to an if block. For example:

{% if false or
      true %}  // can't have multiline if!
  <p>hello world</p>
{% endif %}

How to fix

You have a syntax error in your Django template. Look for missing endif or other closing tags. Don't break lines inside the value of a if or with tag, like on the How to reproduce example above.