我定义了此模型
from django.db import models
from django.db.models import CharField
# Create your models here.
class City(models.Model):
state = models.ForeignKey('state.State',on_delete=models.CASCADE,)
city_name = models.CharField(max_length=100, verbose_name=_('City Name'))
def __unicode__(self, ):
return str(self.city_name)
但是当我要使用它时,出现此错误 在城市
city_name = models.CharField(max_length=100, verbose_name=_('City Name'))
NameError: name '_' is not defined
我不知道问题出在哪里
答案 0 :(得分:2)
您需要导入gettex或替代函数from django.utils.translation import gettext as _
。看看django i18n documentation