如何在django 1.5中修复localflavor弃用警告?

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

I've migrated an existing django 1.3 to django 1.5. everything seems ok. However, I have a deprecation warning due to localflavor when i lauch python manage.py runserver

我已将现有的django 1.3迁移到django 1.5。一切似乎都好。但是,当我使用python manage.py runserver时,由于localflavor,我有一个弃用警告

...\env\lib\site-packages\django\contrib\loca lflavor__init__.py:2: DeprecationWarning: django.contrib.localflavor is deprecated. Use the separate django-localflavor-* packages instead.
warnings.warn("django.contrib.localflavor is deprecated. Use the separate djan go-localflavor-* packages instead.", DeprecationWarning)

... \ env \ lib \ site-packages \ django \ contrib \ loca lflavor__init__.py:2:DreprecationWarning:不推荐使用django.contrib.localflavor。请改用单独的django-localflavor- *软件包。 warnings.warn(“django.contrib.localflavor已弃用。请改用单独的djan go-localflavor- *包。”,DeprecationWarning)

I've read the django 1.5 release note and I understand that this app is now deprecated. My problem is that I don't use the localflavor app in my project.

我已经阅读了django 1.5发行说明,我知道这个应用程序现已弃用。我的问题是我没有在我的项目中使用localflavor应用程序。

I imagine that another app is loading it somehow (maybe localeurl or modeltranslation?) but I don't ho wto fix this warning.

我想,另一个应用程序正在以某种方式加载它(可能是localeurl或modeltranslation?)但我不会修复此警告。

  • How to know why this warning is shown?
  • 如何知道为什么会显示此警告?
  • How to fix it in a clean way?
  • 如何以干净的方式解决它?

3 个解决方案

#1


6  

This is a bug in django 1.5. Django itself is triggering the warning.

这是django 1.5中的一个错误。 Django本身正在触发警告。

The culprit is django/contrib/gis/utils/layermapping.py#L19

罪魁祸首是django / contrib / gis / utils / layermapping.py#L19

This is fixed in django master (via removing localflavor altogether).

这是在django master中修复的(通过完全删除localflavor)。

You can silence the warning by adding an ignore to your logging config:

您可以通过向日志配置添加忽略来使警告静音:

import warnings
warnings.filterwarnings('ignore', r"django.contrib.localflavor is deprecated")

#2


6  

Update:

更新:

Django now have a single localflavors package: https://pypi.python.org/pypi/django-localflavor

Django现在有一个localflavors包:https://pypi.python.org/pypi/django-localflavor

here is the documentation: http://django-localflavor.readthedocs.org/en/latest/

这是文档:http://django-localflavor.readthedocs.org/en/latest/

I let the rest of the response but it is obsolete now.

我让其余的回复但现在已经过时了。

You have to download ALL local flavors you use ( https://github.com/django/ ), for now only 3 are on pypi.

你必须下载你使用的所有本地口味(https://github.com/django/),现在只有3个在pypi上。

Then, you can use them with the new

然后,您可以将它们与新的一起使用

from django_localflavor_XX import forms as XX_forms

(where xx is your favorite country code)

(其中xx是您最喜欢的国家代码)

They choosed to put aside all those libs because a lot of commits (in foreign languages) cames in django and the releases cycles was a bit long.

他们选择放弃所有这些库,因为许多提交(使用外语)来自django并且发布周期有点长。

Django had natively mexican social security number validation widget!

Django原生墨西哥社会安全号验证小部件!

So it's a good move but all those packages need to be managed by local communities as soon as possible to be usable.

所以这是一个很好的举措,但所有这些包都需要尽快由当地社区管理才能使用。

this is trigered when an import is done, you may want to log a stack trace of the import or to look if you depends on a django app who uses it.

导入完成时会出现这种情况,您可能需要记录导入的堆栈跟踪,或者查看是否依赖于使用它的django应用程序。

So open your django sources, go to your contrib.localflavor __init__.py file. print a stacktrace to know where is the bad import.

所以打开你的django源代码,转到你的contrib.localflavor __init__.py文件。打印堆栈跟踪以了解错误导入的位置。

http://docs.python.org/2/library/traceback.html

http://docs.python.org/2/library/traceback.html

Hope it helps

希望能帮助到你

#3


2  

Just dealt with the same issue. I installed the new package (example for US package):

刚刚处理同样的问题。我安装了新包(美国包的示例):

pip install https://github.com/django/django-localflavor-us/zipball/master

点子安装https://github.com/django/django-localflavor-us/zipball/master

then I commented out the old code and changed to the new package:

然后我注释掉旧代码并更改为新包:

# from django.contrib.localflavor.us.us_states import STATE_CHOICES  <= old
from django_localflavor_us.us_states import STATE_CHOICES
# from django.contrib.localflavor.us.models import USStateField  <= old
from django_localflavor_us.models import USStateField

Seems to have fixed the issue. The other language packages are listed here: https://github.com/django

似乎已经解决了这个问题。其他语言包列在这里:https://github.com/django

#1


6  

This is a bug in django 1.5. Django itself is triggering the warning.

这是django 1.5中的一个错误。 Django本身正在触发警告。

The culprit is django/contrib/gis/utils/layermapping.py#L19

罪魁祸首是django / contrib / gis / utils / layermapping.py#L19

This is fixed in django master (via removing localflavor altogether).

这是在django master中修复的(通过完全删除localflavor)。

You can silence the warning by adding an ignore to your logging config:

您可以通过向日志配置添加忽略来使警告静音:

import warnings
warnings.filterwarnings('ignore', r"django.contrib.localflavor is deprecated")

#2


6  

Update:

更新:

Django now have a single localflavors package: https://pypi.python.org/pypi/django-localflavor

Django现在有一个localflavors包:https://pypi.python.org/pypi/django-localflavor

here is the documentation: http://django-localflavor.readthedocs.org/en/latest/

这是文档:http://django-localflavor.readthedocs.org/en/latest/

I let the rest of the response but it is obsolete now.

我让其余的回复但现在已经过时了。

You have to download ALL local flavors you use ( https://github.com/django/ ), for now only 3 are on pypi.

你必须下载你使用的所有本地口味(https://github.com/django/),现在只有3个在pypi上。

Then, you can use them with the new

然后,您可以将它们与新的一起使用

from django_localflavor_XX import forms as XX_forms

(where xx is your favorite country code)

(其中xx是您最喜欢的国家代码)

They choosed to put aside all those libs because a lot of commits (in foreign languages) cames in django and the releases cycles was a bit long.

他们选择放弃所有这些库,因为许多提交(使用外语)来自django并且发布周期有点长。

Django had natively mexican social security number validation widget!

Django原生墨西哥社会安全号验证小部件!

So it's a good move but all those packages need to be managed by local communities as soon as possible to be usable.

所以这是一个很好的举措,但所有这些包都需要尽快由当地社区管理才能使用。

this is trigered when an import is done, you may want to log a stack trace of the import or to look if you depends on a django app who uses it.

导入完成时会出现这种情况,您可能需要记录导入的堆栈跟踪,或者查看是否依赖于使用它的django应用程序。

So open your django sources, go to your contrib.localflavor __init__.py file. print a stacktrace to know where is the bad import.

所以打开你的django源代码,转到你的contrib.localflavor __init__.py文件。打印堆栈跟踪以了解错误导入的位置。

http://docs.python.org/2/library/traceback.html

http://docs.python.org/2/library/traceback.html

Hope it helps

希望能帮助到你

#3


2  

Just dealt with the same issue. I installed the new package (example for US package):

刚刚处理同样的问题。我安装了新包(美国包的示例):

pip install https://github.com/django/django-localflavor-us/zipball/master

点子安装https://github.com/django/django-localflavor-us/zipball/master

then I commented out the old code and changed to the new package:

然后我注释掉旧代码并更改为新包:

# from django.contrib.localflavor.us.us_states import STATE_CHOICES  <= old
from django_localflavor_us.us_states import STATE_CHOICES
# from django.contrib.localflavor.us.models import USStateField  <= old
from django_localflavor_us.models import USStateField

Seems to have fixed the issue. The other language packages are listed here: https://github.com/django

似乎已经解决了这个问题。其他语言包列在这里:https://github.com/django