更新django从1.4到1.5.1;现在在setup_environ上弃用警告

时间:2021-04-28 19:21:55

updated django from 1.4 to 1.5.1 now its throwing this:

更新django从1.4到1.5.1现在抛出这个:

DeprecationWarning: The 'setup_environ' function is deprecated, you likely need to update your 'manage.py'; please see the Django 1.4 release notes (https://docs.djangoproject.com/en/dev/releases/1.4/).

弃用警告:不推荐使用'setup_environ'功能,您可能需要更新'manage.py';请参阅Django 1.4发行说明(https://docs.djangoproject.com/en/dev/releases/1.4/)。

First, I was already on v1.4 so why its showing this now? well..

首先,我已经在v1.4了,为什么它现在显示呢?好..

manage.py already have this:

manage.py已经有了这个:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

but few apps using this:

但使用此功能的应用很少:

from django.core.management import setup_environ
from mysite import settings
setup_environ(settings)

if I comment the above code it throws an error:

如果我评论上面的代码,它会抛出一个错误:

django.core.exceptions.ImproperlyConfigured: Requested setting AUTH_USER_MODEL, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

django.core.exceptions.ImproperlyConfigured:请求设置AUTH_USER_MODEL,但未配置设置。您必须在访问设置之前定义环境变量DJANGO_SETTINGS_MODULE或调用settings.configure()。

so, I called 'settings.configure' and replaced the above code with:

所以,我调用了'settings.configure'并将上面的代码替换为:

from django.conf import settings
from mysite import settings as mysettings
settings.configure(mysettings, DEBUG=True)

but it's still throwing as error!

但它仍然是错误的!

AttributeError: 'module' object has no attribute 'LOGGING_CONFIG'

AttributeError:'module'对象没有属性'LOGGING_CONFIG'

basically 'setup_environ' is working but with the DeprecationWarning, how can I get ride of it? Obviously, I red the release notes 1.4 but can't figure this out..

基本上'setup_environ'正在运行,但是通过DeprecationWarning,我怎样才能获得它?显然,我发布了1.4的发布说明,但无法弄清楚这一点。

1 个解决方案

#1


8  

I end up adding:

我最后添加:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") 

not only to my manage.py file, but also in the app files where I was calling 'setup_environ'. So, I replace this code:

不仅是我的manage.py文件,还有我称之为'setup_environ'的app文件。所以,我替换了这段代码:

from django.core.management import setup_environ
from mysite import settings
setup_environ(settings)

with:

有:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") 

No DeprecationWarning and seems like its working!

没有弃权警告,看起来像它的工作!

#1


8  

I end up adding:

我最后添加:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") 

not only to my manage.py file, but also in the app files where I was calling 'setup_environ'. So, I replace this code:

不仅是我的manage.py文件,还有我称之为'setup_environ'的app文件。所以,我替换了这段代码:

from django.core.management import setup_environ
from mysite import settings
setup_environ(settings)

with:

有:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") 

No DeprecationWarning and seems like its working!

没有弃权警告,看起来像它的工作!