Django Allauth Encountered a new error that I haven' t seen before TemplateSyntaxError at /accounts/login/ Invalid block tag on line 15: 'trans', expected 'elif', 'else' or 'endif'. Did you forget to register or load this tag?

When i am logged in to my admin dashboard i am able to access the profile page in the font-end while logged in–but when i log out and try to login, or use other Allauth links i get this error

TemplateSyntaxError at /accounts/login/

Invalid block tag on line 15: 'trans', expected 'elif', 'else' or 'endif'. Did you forget to register or load this tag?

Traceback

Environment:


Request Method: GET
Request URL: http://127.0.0.1:9999/accounts/login/

Django Version: 4.0
Python Version: 3.10.7
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'derdtalav_app.apps.DerdtalavAppConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template /Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/allauth/templates/account/base.html, error at line 15
   Invalid block tag on line 15: 'trans', expected 'elif', 'else' or 'endif'. Did you forget to register or load this tag?
   5 :     <meta name="viewport" content="width=device-width, initial-scale=1.0">
   6 :     <title>{% block head_title %}{% endblock %}</title>
   7 :     {% block extra_head %}
   8 :     {% endblock %}
   9 :   </head>
   10 :   <body>
   11 :     {% block body %}
   12 : 
   13 :     {% if messages %}
   14 :     <div>
   15 :       <strong> {% trans "Messages:" %} </strong>
   16 :       <ul>
   17 :         {% for message in messages %}
   18 :         <li>{{message}}</li>
   19 :         {% endfor %}
   20 :       </ul>
   21 :     </div>
   22 :     {% endif %}
   23 : 
   24 :     <div>
   25 :       <strong>{% trans "Menu:" %}</strong>


Traceback (most recent call last):
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 500, in parse
    compile_func = self.tags[command]

During handling of the above exception ('trans'), another exception occurred:
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/core/handlers/base.py", line 204, in _get_response
    response = response.render()
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 176, in render
    return self._render(context)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 168, in _render
    return self.nodelist.render(context)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 977, in render
    return SafeString(''.join([
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 978, in <listcomp>
    node.render_annotated(context) for node in self
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 938, in render_annotated
    return self.render(context)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/loader_tags.py", line 130, in render
    compiled_parent = self.get_parent(context)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/loader_tags.py", line 127, in get_parent
    return self.find_template(parent, context)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/loader_tags.py", line 106, in find_template
    template, origin = context.template.engine.find_template(
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/engine.py", line 145, in find_template
    template = loader.get_template(name, skip=skip)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/loaders/base.py", line 29, in get_template
    return Template(
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 155, in __init__
    self.nodelist = self.compile_nodelist()
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 199, in compile_nodelist
    return parser.parse()
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 508, in parse
    raise self.error(token, e)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 506, in parse
    compiled_result = compile_func(self, token)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/loader_tags.py", line 222, in do_block
    nodelist = parser.parse(('endblock',))
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 508, in parse
    raise self.error(token, e)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 506, in parse
    compiled_result = compile_func(self, token)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/defaulttags.py", line 905, in do_if
    nodelist = parser.parse(('elif', 'else', 'endif'))
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 502, in parse
    self.invalid_block_tag(token, command, parse_until)
  File "/Users/ariethan/Documents/django_apps/abc/virt/lib/python3.10/site-packages/django/template/base.py", line 552, in invalid_block_tag
    raise self.error(

Exception Type: TemplateSyntaxError at /accounts/login/
Exception Value: Invalid block tag on line 15: 'trans', expected 'elif', 'else' or 'endif'. Did you forget to register or load this tag?


Has anyone seen this before? This started happening today. Everything worked perfectly with allatuh til this point.

I even attempted to redo everything over by starting new projects and the issue still persists.

Thank you

1 Like

According to the error “Did you forget to register or load this tag?” it’s quite possible that you forgot to add the {% load i18n %} to the beginning of the file.

This tag needs to be loaded in all templates which use translations, even those templates that extend from other templates which have already loaded the i18n tag.
Translation | Django documentation | Django

If this template is included in the django-allauth package, how can we edit it to include the {% load i18n %} line to the template?

You need to overwrite the template. In short, there are two ways to do it (with App level templates and with project templates level) this depends on the current configuration of your project, and you can see more details of each strategy in the Django Documentation

Practically what you should do is create your our version of the auth/login.html template in some templates directory, you can take as inspiration the current implementation of the template in the django-allauth package


Edit: I thought twice and I think it doesn’t make sense that this template has an error if it was implemented by django-allauth (it would be a bug that probably would have been fixed already). Rather the template was overwritten and the error is in that part.

set in settings

USE_I18N = True

I obtain the same error. None of the described recommendations helped and the same error persists. However, it would seem to be an issues with the newest version as discussed over here. So downgrading to 0.52.0 fixed the issue.

Did not change anything…