cannot import name 'ugettext_lazy' from 'django.utils.translation'


问题:

from django.utils.translation import ugettext_lazy as _
ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' (C:\Python38\lib\site-packages\django\utils\translation\__init__.py)

 

解决方法:

采用低版本的Django,比如 Django 2.X

 

==============================

'ugettext_lazy' has been deprecated for django 3+ so you won’t be able to use that with a django version >= 3. https://code.djangoproject.com/ticket/30165

==============================

One answer is ugettext_lazy has been removed in Django 4.0 57. Please use gettext_lazy instead ""

from django.utils.translation import gettext_lazy as _ 

 

==============================
 

I have solved the problem by installing the django==3.2 instead of the latest version of Django. But I`ll still check for the pypi update for the usage in the latest version of Django.

==============================

 

 

REF

https://stackoverflow.com/questions/70656495/importerror-cannot-import-name-ugettext-lazy

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM