Reputation: 7428
I'm trying to customise the label for a django model form:
class SupplyTypeForm(forms.ModelForm):
class Meta:
model = EUser
fields = ('service_type', 'online_account')
labels = {
'online_account': _('Do you have an online account with any of your suppliers'),
}
But I get the error: NameError: name '_' is not defined
However the django docs mention to do it this way, so I'm not clear what's wrong (the underscore is strange and I'm not sure why it is being used here). If I remove it works and the error disappears
Any reason why the docs have it: https://docs.djangoproject.com/en/stable/topics/forms/modelforms/#overriding-the-default-fields
Upvotes: 2
Views: 200
Reputation: 11961
You need to make sure you have the correct import:
from django.utils.translation import ugettext_lazy as _
Upvotes: 5
Reputation: 2413
You should add from django.utils.translation import ugettext as _
to use _()
Upvotes: 1