gpt4 book ai didi

python - 导入错误 : No module named localflavor. br.br_states

转载 作者:太空宇宙 更新时间:2023-11-04 01:11:17 25 4
gpt4 key购买 nike

我使用的是 django 1.6b 和 python 2.7.5,我得到了这个导入错误,

# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.localflavor.br.br_states import STATE_CHOICES
class Contato(models.Model):
SEXO_CHOICES = (
(u'masculino', u'Masculino'),
(u'feminino', u'Feminino'),
)
ESTADO_CIVIL_CHOICES = (
(u'solteiro', u'Solteiro'),
(u'casado', u'Casado'),
(u'divorciado', u'Divorciado'),
(u'viuvo', u'Viúvo'),
)
contato_id = models.AutoField(primary_key=True)
contato_nome = models.CharField(max_length=45, verbose_name='Nome')
contato_nascimento = models.DateField(verbose_name='Data de Nascimento')
contato_sexo = models.CharField(max_length=10, choices=SEXO_CHOICES, verbose_name='Sexo')
contato_estado_civil = models.CharField(max_length=10, choices=ESTADO_CIVIL_CHOICES, verbose_name='Estado Civil')
contato_foto = models.ImageField(max_length=255, blank=True, upload_to='contato/%Y', verbose_name='Foto')
contato_email = models.EmailField(max_length=255, blank=True, verbose_name='Email')
contato_site = models.URLField(max_length=255, blank=True, verbose_name='Site')
contato_observacoes = models.TextField(blank=True, verbose_name='Observações')
contato_favorito = models.BooleanField(verbose_name='Favorito')
def __unicode__(self):
return self.contato_nome
class Meta:
db_table = u'contato'
verbose_name = 'Contato'
verbose_name_plural = 'Contatos'
ordering = ['contato_nome']
class Endereco(models.Model):
TIPO_LOGRADOURO_CHOICES = (
(u'rua', u'Rua'),
(u'avenida', u'Avenida'),
(u'travessa', u'Travessa'),
)
endereco_id = models.AutoField(primary_key=True)
contato = models.ForeignKey(Contato)
endereco_tipo_logradouro = models.CharField(max_length=10, choices=TIPO_LOGRADOURO_CHOICES, verbose_name='Tipo Logradouro')
endereco_logradouro = models.CharField(max_length=80, verbose_name='Logradouro')
endereco_numero = models.IntegerField(verbose_name='Número')
endereco_complemento = models.CharField(max_length=45, blank=True, verbose_name='Complemento')
endereco_bairro = models.CharField(max_length=80, verbose_name='Bairro')
endereco_cidade = models.CharField(max_length=80, verbose_name='Cidade')
endereco_estado = models.CharField(max_length=2, choices=STATE_CHOICES, verbose_name='Estado')
endereco_cep = models.CharField(max_length=9, blank=True, verbose_name='CEP')
def __unicode__(self):
return '%s %s, %s, %s, %s - %s' % (self.endereco_tipo_logradouro, self.endereco_logradouro, self.endereco_numero, self.endereco_bairro, self.endereco_cidade, self.endereco_estado)
class Meta:
db_table = u'endereco'
verbose_name = 'Endereço'
verbose_name_plural = 'Endereços'
ordering = ['endereco_tipo_logradouro']
class Telefone(models.Model):
TELEFONE_TIPO_CHOICES = (
(u'residencial', u'Residencial'),
(u'celular', u'Celular'),
(u'comercial', u'Comercial'),
)
telefone_id = models.AutoField(primary_key=True)
contato = models.ForeignKey(Contato)
telefone_tipo = models.CharField(max_length=15, choices=TELEFONE_TIPO_CHOICES, verbose_name='Tipo')
telefone_numero = models.CharField(max_length=135, verbose_name='Número')
def __unicode__(self):
return self.telefone_numero
class Meta:
db_table = u'telefone'

导入错误:

python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 284, in execute
self.validate()
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/usr/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in _populate
self.load_app(app_name)
File "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/home/localuser/agenda/contato/models.py", line 3, in <module>
from django.contrib.localflavor.br.br_states import STATE_CHOICES
ImportError: No module named localflavor.br.br_states

我已经尝试使用 django 1.6.2 创建一个应用程序,但我发现“导入”有问题正在寻找文档,但我什么也没找到。现在我不会为我的地址模型使用 django 助手,但我不确定是什么导致了这个导入异常。

最佳答案

它移动了:

更改应用的导入语句以引用新包。

例如,改变这个:

from django.contrib.localflavor.fr.forms import FRPhoneNumberField

...为此:

from localflavor.fr.forms import FRPhoneNumberField

请参阅文档:http://django.readthedocs.org/en/1.6.x/topics/localflavor.html#how-to-migrate

关于python - 导入错误 : No module named localflavor. br.br_states,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27490712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com