ImportError, что я не импортировал

Пожалуйста, кто-нибудь должен мне помочь. Я не импортировал ugettext_lazy ниоткуда в моем проекте, я использую django 4.2.1. Я просто установил django-messages, после чего я не могу продолжить работу над проектом. Эта ошибка продолжает появляться в одном месте. Я проверил весь мой импорт, чтобы увидеть, где ugettext_lazy приходит из, но я не смог отследить его. Я даже понизил django 4 до django 3, но я все еще имел некоторую ошибку импорта в django 3. Я обновил его снова до django 4. пожалуйста, помогите мне. спасибо

вот мои импорты views.py

    # from http.client import HTTPResponse
# from django.contrib.auth import login
from django.shortcuts import redirect, render
 
from .forms import CustomUserCreationForm, PostForm, CommentForm, NovenaCommentForm
from . models import About_us, My_blog, Like, Comment, Slider, Prayers, Description, Novena, NovenaComment

from django.urls import reverse
from django.http import HttpResponseRedirect
from django.core.paginator import Paginator,  EmptyPage, PageNotAnInteger
from . like import new_likes, authmessage
from django.contrib import messages
from django.http import HttpResponse
from django.urls import reverse_lazy
from django.contrib.auth.models import User, auth
from django.contrib.auth import authenticate
# from django.contrib import messages
from django.views.generic import ListView, DetailView, DeleteView
from django.contrib.auth.decorators import login_required, user_passes_test, permission_required
from authentications.message import infor

это импорт администратора

from django.contrib import admin
from . models import My_blog, Comment,Slider,Prayers,Description,Novena,Like,About_us,NovenaComment,SubscribedUser

вот мой models.py

from email.mime import image
from time import timezone
from turtle import title
from django.db import models

from django.contrib.auth.models import User

это установка django_message в моем install_app

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',
    'crispy_forms',
    'authentications',
    'django_messages'
]

это полная ошибка

C:\Users\Christopher\Better_world_blog>python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 115, in inner_run
    autoreload.raise_last_exception()
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\__init__.py",
line 381, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\apps\registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\apps\config.py", line 123, in
create
    mod = import_module(mod_path)
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django_messages\apps.py", line 2, in
<module>
    from django.utils.translation import ugettext_lazy as _
ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' (C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\translation\__init__.py)

Это не относится к вашему проекту, а к самому django, потому что ugettext_lazy было удалено в Django 4.0. Просто используйте gettext_lazy вместо этого:

Возможное решение :

открыть: /opt/homebrew/lib/python3.9/site-packages/jsonfield/fields.py

измените строку 9 на:

from django.utils.translation import ugettext_lazy as _

to:

from django.utils.translation import gettext_lazy as _

И вы сможете запустить Django

Проблема не в вашем коде , а в пакете django_messages, который вы установили

File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django_messages\apps.py", line 2

Вы можете исправить эту ошибку вручную, переопределив пакет, но ошибка возвращается каждый раз, когда вы устанавливаете пакет снова (в другой среде)

  • Мое предложение - создать новый вопрос для django_messages или попытаться исправить ошибку и сделать запрос на слияние.
  • или использовать django 2.2, как указано автором пакета в README пакета.
  • или использовать другой пакет ...
Вернуться на верх