Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does '_' do in Django code?

Why does this Django code use _ in front of 'has favicon'

has_favicon = models.BooleanField(_('has favicon'))
like image 268
zjm1126 Avatar asked Dec 26 '09 00:12

zjm1126


2 Answers

If you look in the import statements, you'll find that they tied _ to a function that turns stuff into unicode and localizes it by writing:

from django.utils.translation import ugettext_lazy as _
like image 67
SapphireSun Avatar answered Oct 10 '22 16:10

SapphireSun


_ in Django is a convention that is used for localizing texts. It is an alias for ugettext_lazy. Read Lazy translation in the docs for more info about it.

like image 24
Joshua Partogi Avatar answered Oct 10 '22 16:10

Joshua Partogi