假设我有这种形式:
class RSVPForm(forms.Form):
attending_dinner= forms.ChoiceField(_('attending_dinner'), choices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
attending_brunch = forms.ChoiceField(choices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
number_of_guests = forms.IntegerField(initial=0)
如何标记字段的名称ex。 attending_dinner进行翻译?
答案 0 :(得分:3)
这是答案:
from django.utils.translation import ugettext, ugettext_lazy as _
class RSVPForm(forms.Form):
attending_dinner= forms.ChoiceField(label=_('attending_dinner'), choices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
attending_brunch = forms.ChoiceField(label=_('attending_brunch'), choices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
number_of_guests = forms.IntegerField(initial=0)
comment = forms.CharField(max_length=255, required=False, widget=forms.Textarea)