Invalid filter: 'length_is' in change_form with Django 5.1
guercusguo opened this issue · 10 comments
Due to:
The length_is template filter is removed in Features removed in 5.1.
In template /env/lib/python3.12/site-packages/jazzmin/templates/admin/includes/fieldset.html
, error at line 22
Invalid filter: 'length_is'
12 | |
---|---|
{{ fieldset.description }} |
Also seeing this - is there a known fix?
This is solution, change your django version, downgrade to 5.0.1
pip3 install django==5.0.1
As a temporary workaround, copy over the file templates/admin/includes/fieldset.html
from jazzmin to your project and replace the length_is
filter as explained in the Django release notes: https://docs.djangoproject.com/en/5.1/releases/4.2/#id1
My working fieldset.html
for Django 5.1 looks like this now:
{% load jazzmin %}
{% if card %}
<div class="card {{ fieldset.classes|cut:"collapse" }}">
{% if card_header and fieldset.name %}
<div class="card-header">
<div class="card-title">
<strong>{{ fieldset.name }}</strong>{% if fieldset.description %} - <i>{{ fieldset.description }}</i>{% endif %}
</div>
</div>
{%elif fieldset.description %}
<div class="card-header">
<div class="card-title">
{{ fieldset.description }}
</div>
</div>
{%endif%}
<div class="p-5{% if fieldset.name %} card-body{% endif %}">
{% endif %}
{% for line in fieldset %}
<div class="form-group{% if line.fields|length == 1 and line.errors %} errors{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}">
<div class="row">
{% for field in line %}
<label class="{% if not line.fields|length == 1 and forloop.counter != 1 %}col-auto {% else %}col-sm-3 {% endif %}text-left" for="id_{{ field.field.name }}">
{{ field.field.label|capfirst }}
{% if field.field.field.required %}
<span class="text-red">* </span>
{% endif %}
</label>
<div class="{% if not line.fields|length == 1 %} col-auto fieldBox {% else %} col-sm-7 {% endif %}
{% if field.field.name %} field-{{ field.field.name }}{% endif %}
{% if not field.is_readonly and field.errors %} errors{% endif %}
{% if field.field.is_hidden %} hidden {% endif %}
{% if field.is_checkcard %} checkcard-row{% endif %}">
{% if field.is_readonly %}
<div class="readonly">{{ field.contents }}</div>
{% else %}
{{ field.field }}
{% endif %}
<div class="help-block red">
{% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %}
</div>
{% if field.field.help_text %}
<div class="help-block">{{ field.field.help_text|safe }}</div>
{% endif %}
<div class="help-block text-red">
{% if line.fields|length == 1 %}{{ line.errors }}{% endif %}
</div>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
{% if card %}
</div>
</div>
{% endif %}
As a temporary workaround, copy over the file
templates/admin/includes/fieldset.html
from jazzmin to your project and replace thelength_is
filter as explained in the Django release notes: https://docs.djangoproject.com/en/5.1/releases/4.2/#id1My working
fieldset.html
for Django 5.1 looks like this now:{% load jazzmin %} {% if card %} <div class="card {{ fieldset.classes|cut:"collapse" }}"> {% if card_header and fieldset.name %} <div class="card-header"> <div class="card-title"> <strong>{{ fieldset.name }}</strong>{% if fieldset.description %} - <i>{{ fieldset.description }}</i>{% endif %} </div> </div> {%elif fieldset.description %} <div class="card-header"> <div class="card-title"> {{ fieldset.description }} </div> </div> {%endif%} <div class="p-5{% if fieldset.name %} card-body{% endif %}"> {% endif %} {% for line in fieldset %} <div class="form-group{% if line.fields|length == 1 and line.errors %} errors{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}"> <div class="row"> {% for field in line %} <label class="{% if not line.fields|length == 1 and forloop.counter != 1 %}col-auto {% else %}col-sm-3 {% endif %}text-left" for="id_{{ field.field.name }}"> {{ field.field.label|capfirst }} {% if field.field.field.required %} <span class="text-red">* </span> {% endif %} </label> <div class="{% if not line.fields|length == 1 %} col-auto fieldBox {% else %} col-sm-7 {% endif %} {% if field.field.name %} field-{{ field.field.name }}{% endif %} {% if not field.is_readonly and field.errors %} errors{% endif %} {% if field.field.is_hidden %} hidden {% endif %} {% if field.is_checkcard %} checkcard-row{% endif %}"> {% if field.is_readonly %} <div class="readonly">{{ field.contents }}</div> {% else %} {{ field.field }} {% endif %} <div class="help-block red"> {% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %} </div> {% if field.field.help_text %} <div class="help-block">{{ field.field.help_text|safe }}</div> {% endif %} <div class="help-block text-red"> {% if line.fields|length == 1 %}{{ line.errors }}{% endif %} </div> </div> {% endfor %} </div> </div> {% endfor %} {% if card %} </div> </div> {% endif %}
Tnxs, i was wondering if I didn't do something right, because I used it 3 weeks ago with Django 5.0 it worked, I was like why
To clarify the above comment, you should have a folder specified in your settings.py file for 'templates':
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'templates',
],
'APP_DIRS': True,
...
}
]
Then copy the file from the previous comment into the 'templates' using the same path as the file in the jazzmin package, like templates\admin\includes\fieldset.html.
Then copy/edit the file so that it matches the above.
Hi, is this fixed there currently SQL Injection(not only) issue with Django==5.0.1 version which is the workaround of this issue.
@farridav
This has been fixed with https://github.com/farridav/django-jazzmin/releases/tag/v3.0.1
Okay, thanks. I will update to this version.