安装 django-admin-charts 后出现关于 smart_text 的错误

发布于 2025-01-16 19:39:41 字数 583 浏览 1 评论 0原文

我想在管理面板中显示图表, 我安装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

百善笑为先 2025-01-23 19:39:42

这是因为 django-admin-charts 需要 smart_text 并且在 django 4 smart_text 中已从 utils/encoding 中删除,因此解决此问题的更好方法是在 settings.py 文件中添加此代码

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

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
故人如初 2025-01-23 19:39:42

我查了一下,问题似乎出在 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 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.

通知家属抬走 2025-01-23 19:39:42

当我们从 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.

烟花肆意 2025-01-23 19:39:42

我遇到了完全相同的问题,对我有用的解决方案是将其添加到我的 settings.py 文件中

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

I had exactly the same problem and the solution that worked for me was adding this to my settings.py file

import django
from django.utils.encoding import smart_str
django.utils.encoding.smart_text = smart_str
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文