模板中的 django 翻译(?)
我在翻译后加了一个(?),因为我不确定这是否是翻译问题。
我有一个如下所示的 UserProfile 模型:
class UserProfile(models.Model) :
GENDER_CHOICES = (('M', _('Male')),
('F', _('Female')))
gender = models.CharField(max_length=2, choices=GENDER_CHOICES, blank=True, null=True)
user = models.ForeignKey(User, unique=True)
以及相应的 UserProfileModelForm。当我使用 form.as_p
显示所述表单时,性别字段显示为下拉选项,并显示“男”和“女”。
现在我想在我的个人资料详细信息模板中显示相同的单词,但是当我执行 {{ profile.gender }}
时,会显示字母“M”和“F”。这当然是预料之中的,因为这是数据库中记录的内容。但是如何让我的个人资料详细信息模板也显示“男性”和“女性”呢?
谢谢!
I put a (?) after translation because I'm not sure if this is a translation issue or not.
I have a UserProfile model that looks like so:
class UserProfile(models.Model) :
GENDER_CHOICES = (('M', _('Male')),
('F', _('Female')))
gender = models.CharField(max_length=2, choices=GENDER_CHOICES, blank=True, null=True)
user = models.ForeignKey(User, unique=True)
as well as a corresponding UserProfileModelForm. When I display said form using form.as_p
the Gender field is shown as a drop-down selection and it displays "Male" and "Female."
Now I want to show the same words in my Profile Detail template, but when I do {{ profile.gender }}
the letters "M" and "F" are displayed. This is as expected of course, because that is what's recorded in the database. But how do I make my Profile Detail template show "Male" and "Female" as well?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行
{{ profile.get_gender_display }}
请参阅此处的文档You can do
{{ profile.get_gender_display }}
See the docs here