0

I'm trying to implement Tags on my project using the django-tagging package.
Below is the full error.\

File "C:\Users<user>\Desktop<App>\models.py", line 9, in from tagging.fields import TagField File "C:\Users<User>\Desktop<User><App>\env\lib\site-packages\tagging\fields.py", line 9, in from tagging.forms import TagField as TagFormField File "C:\Users<User>\Desktop<User><App>\env\lib\site-packages\tagging\forms.py", line 8, in from tagging.models import Tag File "C:\Users<User>\Desktop<User><App>\env\lib\site-packages\tagging\models.py", line 8, in from django.utils.encoding import smart_text ImportError: cannot import name 'smart_text' from 'django.utils.encoding' ("C:\Users<User>\Desktop<User><App>\env\lib\site-packages\django\utils\encoding.py)

models.py\

class ModelName(models.Model):
     .....
     tags = TagField()

Working with django.VERSION (4, 2, 0, 'final', 0)

Karimi254
  • 105
  • 1
  • 8
  • Does this answer your question? [I have an error about smart\_text after installing django-admin-charts](https://stackoverflow.com/questions/71589827/i-have-an-error-about-smart-text-after-installing-django-admin-charts) – PTomasz Apr 05 '23 at 13:23

1 Answers1

0

This error is caused by the removal of smart_text from django.utils.encoding in Django 4.0.21. The error message is raised when a package that depends on smart_text is used with Django 4.0.2 or later1.

Solution Add this code in your settings.py file1:

import django
from django.utils.encoding import smart_str
django.utils.encoding.smart_text = smart_str
Karimi254
  • 105
  • 1
  • 8