Please someone should help me out. I did not import ugettext_lazy from anywhere in my project am using django 4.2.1. i just install django-messages from then i cannot proceed with my project. this error keep showing an am stock in one place. I check all my import to see where the ugettext_lazy is comming from but i could not trace it. i even downgrade django 4 to django 3 but i was still having some import error in django 3. i upgrade it again to django 4. please help me out. thanks
this is my views.py imports
# 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
this is admin imports
from django.contrib import admin
from . models import My_blog, Comment,Slider,Prayers,Description,Novena,Like,About_us,NovenaComment,SubscribedUser
this is my 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
this is the django_message install in my 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'
]
this is the compleate error
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)
CodePudding user response:
The problem is not from your code it's from django_messages
package that you installed
File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django_messages\apps.py", line 2
You can fix this bug manually by overriding the package but the bug gets back every time you install the package again (in another environment)
- My suggestion is that create a new issue for django_messages or try to fix the bug and merge request it.
- or use django 2.2 as the author of the package mentioned in the README of the package.
- or use another package ...
CodePudding user response:
This is not related to your project but django it self because ugettext_lazy
has been removed in Django 4.0 . Just use gettext_lazy
instead .
possible solution :
in django-messages open field.py in line 8 change :
from django.utils.translation import ugettext_lazy as _
to : from django.utils.translation import gettext_lazy as _