How to fix localflavor deprecation warning in django 1.5?
Asked Answered
F

3

8

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

...\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)

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.

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

  • How to know why this warning is shown?
  • How to fix it in a clean way?
Finke answered 7/3, 2013 at 17:22 Comment(1)
I ended up here due to this identical error message but it was actually due to using localflavor, the title was a bit misleading since this has already been fixed in the latest release of Django but wasn't the same problem ... answers are still provided for both problems.Languor
D
6

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

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

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

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

import warnings
warnings.filterwarnings('ignore', r"django.contrib.localflavor is deprecated")
Delaunay answered 8/3, 2013 at 1:16 Comment(0)
T
6

Update:

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

here is the documentation: 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.

Then, you can use them with the new

from django_localflavor_XX import forms as XX_forms

(where xx is your favorite country code)

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 had natively mexican social security number validation widget!

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.

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

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

Hope it helps

Thursby answered 7/3, 2013 at 17:30 Comment(1)
Thanks. I'll try to find what is importing it.Finke
D
6

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

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

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

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

import warnings
warnings.filterwarnings('ignore', r"django.contrib.localflavor is deprecated")
Delaunay answered 8/3, 2013 at 1:16 Comment(0)
I
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

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

Illfated answered 10/3, 2013 at 0:4 Comment(1)
You may also need to remove 'django.contrib.localflavor' from INSTALLED_APPS in your settings.py.Baronetcy

© 2022 - 2024 — McMap. All rights reserved.