'verbose_name': _('Small screens') NameError: name '_' is not defined

After installation django-responsive2 as django-responsive2, i got following error:

'verbose_name': _('Small screens')
NameError: name '_' is not defined

I use from django.utils.translation import gettext_lazy as _. I got this error:

mw_instance = middleware(adapted_handler)
TypeError: object() takes no parameters 

Next i used

from django.utils.translation import gettext_lazy
'verbose_name': gettext_lazy('Small screens')

but i got previous error again. finally i used 'verbose_name': 'Small screens' and got this error:

enter image description here

MIDDLEWARE is:

MIDDLEWARE = [
        'django.middleware.security.SecurityMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
        'responsive.middleware.ResponsiveMiddleware',
    ]

In Django _ is used as a short identifier to refer to the gettext_lazy(…) function [Django-doc]. You need to import this (at the top of your file):

from django.utils.translation import gettext_lazy as _

You can also import this simply as gettext_lazy and then use this later in the program:

from django.utils.translation import gettext_lazy

# …

'verbose_name': gettext_lazy('Small screens')

Or if you do not plan to make your app available in other languages, you just use the string literal, so removing the _(…) part:

'verbose_name': 'Small screens'
Back to Top