I have an error about smart_text after installing django-admin-charts

12.4k Views Asked by At

I want to have charts in the admin panel, I installed the django-admin-charts package, Which said add these to settings.py

INSTALLED_APPS = (
         'admin_tools_stats', # this must be BEFORE 'admin_tools' and 'django.contrib.admin'
         'django_nvd3',
)

But after adding it, it gives this error:

ImportError: cannot import name 'smart_text' from 'django.utils.encoding' (E: \ test1 \ venv1 \ lib \ site-packages \ django \ utils \ encoding.py)

I searched but didn't find much about smart_text! Maybe it has a problem with Django version 4 or Python version 3.10.3?

3

There are 3 best solutions below

0
On

I digged around a little and the problem seems to be the Django version. smart_text function is not present in the django/utils/encoding.py file. I downgraded from 4.0.2 to 3.2.13, set PyMemcacheCache as the default cache in settings.py and it works. In my case downgrading is not acceptable as Django. 3.2.13 doesn't support redis cache, but it might help you. Let's hope that django-admin-charts will add suport for Django 4.0.

0
On

This is because django-admin-charts needs smart_text and in django 4 smart_text is removed from the utils/encoding so the better way to resolve this issue is to add this code in your settings.py file

import django
from django.utils.encoding import smart_str
django.utils.encoding.smart_text = smart_str
0
On

I got this error when we switched from Django 2.2 to Django 4 version. There were a library which was not upgraded. I found this out by searching the usage of "django.utils.encoding import smart_text" statement under the project scope.

The issue resolved once I upgraded the django-wkhtmltopdf library from 3.3.0 to 3.4.0.

Check for any dependent libraries and upgrade as above to fix the issue.