安装 django-admin-charts 后出现关于 smart_text 的错误
我想在管理面板中显示图表, 我安装了 django-admin-charts
包, 其中说将这些添加到 settings.py
INSTALLED_APPS = (
'admin_tools_stats', # this must be BEFORE 'admin_tools' and 'django.contrib.admin'
'django_nvd3',
)
但添加后,它给出了这个错误:
ImportError: cannot import name 'smart_text' from 'django.utils.encoding' (E: \ test1 \ venv1 \ lib \ site-packages \ django \ utils \ encoding.py)
我搜索但没有找到太多关于 smart_text 的信息! 也许 Django 版本 4 或 Python 版本 3.10.3 有问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是因为 django-admin-charts 需要 smart_text 并且在 django 4 smart_text 中已从 utils/encoding 中删除,因此解决此问题的更好方法是在 settings.py 文件中添加此代码
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
我查了一下,问题似乎出在 Django 版本上。
django/utils/encoding.py
文件中不存在smart_text
函数。我从 4.0.2 降级到 3.2.13,在 settings.py 中将 PyMemcacheCache 设置为默认缓存,它可以工作。就我而言,降级作为 Django 是不可接受的。 3.2.13不支持redis缓存,但它可能对你有帮助。我们希望 django-admin-charts 能够添加对 Django 4.0 的支持。I digged around a little and the problem seems to be the Django version.
smart_text
function is not present in thedjango/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.当我们从 Django 2.2 切换到 Django 4 版本时,我收到此错误。
有一个图书馆没有升级。我通过在项目范围下搜索“django.utils.encoding import smart_text”语句的用法发现了这一点。
当我将 django-wkhtmltopdf 库从 3.3.0 升级到 3.4.0 后,问题就解决了。
检查是否有任何依赖库并按照上述方式升级以解决问题。
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.
我遇到了完全相同的问题,对我有用的解决方案是将其添加到我的 settings.py 文件中
I had exactly the same problem and the solution that worked for me was adding this to my settings.py file