Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError No module named localflavor.us.forms in Django 1.7

I recently upgraded to Django 1.7.4 and had to change the deprecated localflavor import.

Here is the new code:

from django import forms
from localflavor.us.forms import USPhoneNumberField

class ContactUsForm(forms.Form):
    first_name = forms.CharField(required=False, label="First Name")
    last_name = forms.CharField(required=False, label="Last Name")
    phone = USPhoneNumberField(required=False, label="Phone")
    email = forms.EmailField(label="Email")
    message = forms.CharField(label="Your Message")

When the code runs, I get an error:

ImportError at /mypage
No module named localflavor.us.forms

Request Method:     GET
Request URL:    http://test.mysite.com/mypage
Django Version:     1.7.4
Exception Type:     ImportError
Exception Value:    

No module named localflavor.us.forms

Exception Location:     /var/www/mysite-test/mysite/apps/marketing/forms.py in <module>, line 2
Python Executable:  /usr/bin/python
Python Version:     2.7.6
Python Path:    

['/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/var/www/mysite-test',
 '/var/www/mysite-test/mysite']
like image 915
Mustafamond77 Avatar asked Feb 19 '15 03:02

Mustafamond77


1 Answers

localflavor is now a third party app (as your import shows).

You must install it: https://github.com/django/django-localflavor

pip install django-localflavor

https://django-localflavor.readthedocs.org/en/latest/#installation

like image 76
Yuji 'Tomita' Tomita Avatar answered Nov 12 '22 22:11

Yuji 'Tomita' Tomita