2

Step 1: I logged into the Django Admin
Step 2: Clicked in Password Change in Admin
Step 3: Entered the Old Password and New Password
Step 4: Clicked the Change My password button

The password is being successfully changed in the database. But, I'm getting the following error:

Environment:


Request Method: GET
Request URL: http://localhost:8000/admin/password_change/done/

Django Version: 2.2.24
Python Version: 3.7.10
Installed Applications:
['material.admin',
 'material.admin.default',
 'nested_inline',
 'django.contrib.auth',
 'django.contrib.sites',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_extensions',
 'softdelete',
 'reversion',
 'actstream',
 'rest_framework',
 'rest_framework.authtoken',
 'valital.api.apps.ApiConfig',
 'cacheops',
 'corsheaders',
 'drf_yasg',
 'storages',
 'djmoney',
 'mail_factory',
 'mjml']
Installed Middleware:
['corsheaders.middleware.CorsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'reversion.middleware.RevisionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template /usr/local/lib/python3.7/site-packages/material/admin/templates/registration/password_change_done.html, error at line 3
   Invalid block tag on line 3: 'translate', expected 'elif', 'else' or 'endif'. Did you forget to register or load this tag?
   1 : {% extends "admin/base_site.html" %}
   2 : {% load i18n %}
   3 : {% block userlinks %}{% url 'django-admindocs-docroot' as docsroot %}{% if docsroot %}<a href="{{ docsroot }}"> {% translate 'Documentation' %} </a> / {% endif %}{% translate 'Change password' %} / <a href="{% url 'admin:logout' %}">{% translate 'Log out' %}</a>{% endblock %}
   4 : {% block breadcrumbs %}
   5 : <div class="breadcrumbs">
   6 : <a href="{% url 'admin:index' %}">{% translate 'Home' %}</a>
   7 : &rsaquo; {% translate 'Password change' %}
   8 : </div>
   9 : {% endblock %}
   10 : 
   11 : {% block content %}
   12 :   <div class="app">
   13 :     <div class="card">


Traceback:

File "/usr/local/lib/python3.7/site-packages/django/template/base.py" in parse
  470.                     compile_func = self.tags[command]

During handling of the above exception ('translate'), another exception occurred:

File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  145.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  143.                 response = response.render()

File "/usr/local/lib/python3.7/site-packages/django/template/response.py" in render
  106.             self.content = self.rendered_content

File "/usr/local/lib/python3.7/site-packages/django/template/response.py" in rendered_content
  81.         template = self.resolve_template(self.template_name)

File "/usr/local/lib/python3.7/site-packages/django/template/response.py" in resolve_template
  63.             return select_template(template, using=self.using)

File "/usr/local/lib/python3.7/site-packages/django/template/loader.py" in select_template
  42.                 return engine.get_template(template_name)

File "/usr/local/lib/python3.7/site-packages/django/template/backends/django.py" in get_template
  34.             return Template(self.engine.get_template(template_name), self)

File "/usr/local/lib/python3.7/site-packages/django/template/engine.py" in get_template
  143.         template, origin = self.find_template(template_name)

File "/usr/local/lib/python3.7/site-packages/django/template/engine.py" in find_template
  125.                 template = loader.get_template(name, skip=skip)

File "/usr/local/lib/python3.7/site-packages/django/template/loaders/base.py" in get_template
  30.                     contents, origin, origin.template_name, self.engine,

File "/usr/local/lib/python3.7/site-packages/django/template/base.py" in __init__
  156.         self.nodelist = self.compile_nodelist()

File "/usr/local/lib/python3.7/site-packages/django/template/base.py" in compile_nodelist
  194.             return parser.parse()

File "/usr/local/lib/python3.7/site-packages/django/template/base.py" in parse
  478.                     raise self.error(token, e)

File "/usr/local/lib/python3.7/site-packages/django/template/base.py" in parse
  476.                     compiled_result = compile_func(self, token)

File "/usr/local/lib/python3.7/site-packages/django/template/loader_tags.py" in do_extends
  266.     nodelist = parser.parse()

File "/usr/local/lib/python3.7/site-packages/django/template/base.py" in parse
  478.                     raise self.error(token, e)

File "/usr/local/lib/python3.7/site-packages/django/template/base.py" in parse
  476.                     compiled_result = compile_func(self, token)

File "/usr/local/lib/python3.7/site-packages/django/template/loader_tags.py" in do_block
  209.     nodelist = parser.parse(('endblock',))

File "/usr/local/lib/python3.7/site-packages/django/template/base.py" in parse
  478.                     raise self.error(token, e)

File "/usr/local/lib/python3.7/site-packages/django/template/base.py" in parse
  476.                     compiled_result = compile_func(self, token)

File "/usr/local/lib/python3.7/site-packages/django/template/defaulttags.py" in do_if
  952.     nodelist = parser.parse(('elif', 'else', 'endif'))

File "/usr/local/lib/python3.7/site-packages/django/template/base.py" in parse
  472.                     self.invalid_block_tag(token, command, parse_until)

File "/usr/local/lib/python3.7/site-packages/django/template/base.py" in invalid_block_tag
  528.                     get_text_list(["'%s'" % p for p in parse_until], 'or'),

Exception Type: TemplateSyntaxError at /admin/password_change/done/
Exception Value: Invalid block tag on line 3: 'translate', expected 'elif', 'else' or 'endif'. Did you forget to register or load this tag?

Can anyone let me know an answer to resolve this?

Sriram
  • 43
  • 4

1 Answers1

1

Your error message says it all:

Exception Value: Invalid block tag on line 3: 'translate', expected 'elif', 'else' or 'endif'.

It seems like the template does not like the translate nested inside the if.

You can override the template and override just the userlinks block

{% block userlinks %}
    {% url 'django-admindocs-docroot' as docsroot %}
    {% if docsroot %}
        <a href="{{ docsroot }}"> {% translate 'Documentation' %} </a>
        /
    {% endif %}
        {% translate 'Change password' %}
        /
        <a href="{% url 'admin:logout' %}">{% translate 'Log out' %}</a>
{% endblock %}

Note https://docs.djangoproject.com/en/3.1/topics/i18n/translation/#translate-template-tag

Changed in Django 3.1:

The trans tag was renamed to translate. The trans tag is still supported as an alias for backwards compatibility.

Ralf
  • 16,086
  • 4
  • 44
  • 68
  • The path that is shown to the file is pointing to the file in Docker container. Since we shouldn't edit the files in docker container, could you let me know where can I find this file in my local machine. I've already tried searching for this file in my local machine but I haven't found anything useful. I found a file in this location "./.local/share/virtualenvs/app-backend-8zqIWoAn/lib/python3.7/site-packages/material/admin/templates/registration/password_change_done.html". When I change this file and saved it, the changes aren't reflecting in the landing page – Sriram Aug 17 '21 at 00:52
  • https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#overriding-vs-replacing-an-admin-template – Ralf Aug 17 '21 at 10:22
  • @Sriram [this question](https://stackoverflow.com/questions/6583877/how-to-override-and-extend-basic-django-admin-templates) might help for overriding templates – Ralf Aug 17 '21 at 10:22
  • Found the error: The system expects the word "tans" instead of "translate" (as you said "It seems like the template does not like the `translate` nested inside the `if`") in the file. Thanks for the response @Ralf – Sriram Aug 18 '21 at 15:11
  • @Sriram I edited my answer to add that info; The tag was renamed in `v3.1`. Apparently you found a bug in one of the templates where the alias does not seem to work right – Ralf Aug 18 '21 at 16:14