ImportError 在 Django 1.7 中没有名为 localflavor.us.forms 的模块

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

我最近升级到 Django 1.7.4,不得不更改已弃用的 localflavor 导入。

这是新代码:

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")

代码运行时出现错误:

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']

localflavor 现在是第三方应用程序(如您的导入所示)。

您必须安装它: https://github.com/django/django-localflavor

pip install django-localflavor

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