pythondjangovalidationerror

"global name '_' is not defined" during raising ValidationError


I'm following django tutorial about raising ValidationError in Django.

Unfortunatelly even the simplest snippet won't work. I've added below code to my validator object:

raise ValidationError(_('Invalid value'), code='invalid')

and got error

global name '_' is not defined

What did I do wrong?


Solution

  • You are missing this line:

    from django.utils.translation import ugettext as _