博主从GitHub上拉取下了一个Django项目,该项目依赖环境为Django==2.2.6版本,而博主本地Anaconda3环境下的Django==4.1.3版本,在终端输入python manage.py runserver启动项目后,提示错误:ImportError: cannot import name ‘ugettext_lazy’ from ‘django.utils.translation’ (D:\ProgramData\Anaconda3\lib\site-packages\django\utils\translation_init_.py)
from django.utils.translation import ugettext_lazy as _
ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' (D:\ProgramData\Anaconda3\lib\site-packages\django\utils\translation\__init__.py)

“ugettext_lazy”已被 Django 3+ 弃用,因此您将无法将其与 Django 版本 >= 3 一起使用 https://code.djangoproject.com/ticket/30165
Along the lines of #27753 (Cleanups when no supported version of Django supports Python 2 anymore), the legacy functions in -- , , , , and -- are simple aliases that remain for Python 2 Unicode backwards compatibility. As other compatibility layers have been cleaned up, these shims can be deprecated for removal.django.utils.translationugettext()ugettext_lazy()ugettext_noop()ungettext()ungettext_lazy()
降低Django版本为Django==2.2.6
pip install Django==2.2.6 -i https://pypi.tuna.tsinghua.edu.cn/simple/
# from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

解决以上错误后,还会提示其他ImportError如:
错误1:ImportError: cannot import name ‘force_unicode’ from ‘django.utils.encoding’ (D:\ProgramData\Anaconda3\lib\site-packages\django\utils\encoding.py)
# from django.utils.encoding import force_unicode as force_text # noqa
from django.utils.encoding import force_str as force_text # noqa
错误2:ImportError: cannot import name ‘ungettext’ from ‘django.utils.translation’ (D:\ProgramData\Anaconda3\lib\site-packages\django\utils\translation_init_.py)
# from django.utils.translation import ungettext, ugettext as _
from django.utils.translation import gettext_lazy, gettext_lazy as _
错误3:ImportError: cannot import name ‘render_to_response’ from ‘django.shortcuts’ (D:\ProgramData\Anaconda3\lib\site-packages\django\shortcuts.py)
# from django.shortcuts import render_to_response
from django.shortcuts import render
最后成功启动项目,问题解决

我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我看到这个错误:translationmissing:da.datetime.distance_in_words.about_x_hours我的语言环境文件:http://pastie.org/2944890我的看法:我已将其添加到我的application.rb中:config.i18n.load_path+=Dir[Rails.root.join('my','locales','*.{rb,yml}').to_s]config.i18n.default_locale=:da如果我删除I18配置,帮助程序会处理英语。更新:我在config/enviorments/devolpment
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
从给定URL下载文件并立即将其上传到AmazonS3的更直接的方法是什么(+将有关文件的一些信息保存到数据库中,例如名称、大小等)?现在,我既不使用Paperclip,也不使用Carrierwave。谢谢 最佳答案 简单明了:require'open-uri'require's3'amazon=S3::Service.new(access_key_id:'KEY',secret_access_key:'KEY')bucket=amazon.buckets.find('image_storage')url='http://www.ex
protect_from_forgery默认Rails6应用程序不包含在我的应用程序Controller中,但是有嵌入式ruby在主应用程序布局中。这是否意味着protect_from_forgery方法已经被抽象并且在应用程序Controller中不再明确需要?我买了实用程序员的Rails6一书,我唯一能找到的是“csrf_meta_tags()方法设置了防止跨站点请求伪造攻击所需的所有幕后数据”。 最佳答案 对于rails5.2和更高版本,默认情况下在ActionController::Base上启用。查看此提交:https
我有以下代码,它下载一个文件,然后将文件的内容读入一个变量。使用该变量,它执行一个命令。这个配方不会收敛,因为/root/foo在编译阶段不存在。我可以通过多个聚合和一个来解决这个问题ifFile.exist但我想用一个收敛来完成它。关于如何做到这一点有什么想法吗?execute'download_joiner'docommand"awss3cps3://bucket/foo/root/foo"not_if{::File.exist?('/root/foo')}endpassword=::File.read('/root/foo').chompexecute'join_domain'd
我编写了一个非常简单的“部署”脚本,作为我的裸git存储库中的post-updateHook运行。变量如下livedomain=~/mydomain.comstagingdomain=~/stage.mydomain.comgitrepolocation=~/git.mydomain.com/thisrepo.git(bare)core=~/git.mydomain.com/thisrepo.gitcore==addedremoteintoeachlive&stagegitslive和stage都初始化了gitrepos(非裸),我已经将我的裸仓库作为远程添加到它们中的每一个(名为co
我想使用两种不同的protect_from_forgery策略构建一个Rails应用程序:一种用于Web应用程序,一种用于API。在我的应用程序Controller中,我有这行代码:protect_from_forgerywith::exception为了防止CSRF攻击,它工作得很好。在我的API命名空间中,我创建了一个继承self的应用程序Controller的api_controller,它是API命名空间中所有其他Controller的父类,我将上面的代码更改为:protect_from_forgery:null_session.遗憾的是,我在尝试发出POST请求时遇到错误:“
我正在处理oauth1.0(twitter和flickr)。网站工作在80端口,oauth服务器工作在8080端口算法:向oauth服务器发送ajax请求以检查用户是否有有效的access_token如果用户没有access_token或access_token已过期,则打开授权窗口在oauth服务器的用户session中保存access_token发送分享数据到oauth服务器它使用sinatra+rack:session+rack::session::sequel+sqlite来存储session。它在每个响应中发送Set-Cookie:rack.session=id我正在使用2种
有人可以帮忙吗?我的堆栈是带有nginx/passenger和ruby2.2.2的ubuntu-server14.04。我无法使我的项目投入生产。在开发中一切运行正常。secret.ymlproduction:secret_key_base:secret_token:服务器server{listen80;server_namelogvs.local;passenger_enabledon;passenger_app_envdevelopment;root/var/www/logvs/public;}错误日志App2532stderr:[2015-06-0722:56:01.4724