Error During Template rendering Invalid Filter: "length_is"

Hello everyone,
I’m facing an issue with my Django project on Heroku that I can’t seem to resolve. The project works perfectly fine locally, but when I deploy it to Heroku and try to access the admin page for adding a new user (/admin/auth/user/add), I get the following error:

Details:

  • 1. Project Name: NyumbaChap
  • 2. Django Version: Django==5.1.1
  • 3. Heroku Stack: heroku-22
  • Error Message: invalid filter length_is : fieldset.html

The issue seems to stem from the Jazzmin package, specifically from a template located in fieldset.html, which is using the length_is filter. I’ve made sure that everything is correctly set up, and I’ve fixed this locally, but on Heroku, it still throws the same error.

What I’ve Tried:

  1. Checked that the template files are included in my project structure.
  2. Verified that the TEMPLATES setting in my settings.py is correctly configured.
  3. Ensured that I have run migrations and set environment variables on Heroku

Traceback summary

TemplateSyntaxError at /admin/auth/user/add/
Invalid filter: ‘length_is’
Request Method: GET
Request URL: https://myambachap1-e021394fbadd.herokuapp.com/admin/auth/user/add/
Django Version: 5.1.1
Exception Type: TemplateSyntaxError
Exception Value: Invalid filter: "length_is
Exception Location: /app/heroku/python/lib/python3.12/site-packages/django/template/base.py, line 611, in find_filter
Raised during: django.contrib.auth.admin.add_view

  • Has anyone else encountered this issue with Heroku deployments?
  • Are there any additional steps or configurations I might be missing?

You should try again with an updated django-jazzmin version:

The length_is issue seems to have been fixed in 3.0.1.

1 Like

How have you fixed the issue locally? Have you edited the file in the virtualenv? Since the Heroku build will reinstall the dependencies’ files from PyPI and not from your local environment the old errors will be back.

1 Like

I changed the code from:
{% if line.fields|length_is:‘1’ and line.errors %}
to
{% if line.fields|length == 1 and line.errors %}

in the fieldset.html file located in the virtual environment, and the problem was resolved. However, after deploying, I encountered the same issue again.

Yes, because the deployment installs from PyPI again, not from your locally modified virtualenv.

2 Likes