Material Admin is based on Google’s Material Design and supports the latest Django versions.
-
Install Material Admin:
pip install django-material-admin
-
Add
material
toINSTALLED_APPS
insettings.py
beforedjango.contrib.admin
:INSTALLED_APPS = [ 'material', 'django.contrib.admin', # other apps ]
-
Start the development server and check the admin interface.
TemplateSyntaxError at /admin/toggle_app/toggleitem/6/change/
Invalid filter: 'length_is'
-
Define the Filter Create a
templatetags
folder (if it doesn’t already exist) in your app, and include an__init__.py
file inside it. Add acustom_filters.py
file.Folder structure:
toggle_app/ ├── templatetags/ │ ├── __init__.py │ ├── custom_filters.py
In
custom_filters.py
, define thelength_is
filter:from django import template register = template.Library() @register.filter def length_is(value, length): """Check if the length of the value is equal to the given length.""" try: return len(value) == int(length) except (ValueError, TypeError): return False
To make the custom filter globally available without needing to {% load custom_filters %}
in each template, register it as a built-in template tag library.
- In your
settings.py
, add:TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], "builtins": ["toggle_app.templatetags.custom_filters"], # Add your custom filters here }, }, ]
After making these changes, restart your Django development server to ensure the changes take effect:
python manage.py collectstatic
python manage.py runserver