What does '_' do in Django code?

a 夏天 提交于 2020-12-29 09:45:10

问题


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

has_favicon = models.BooleanField(_('has favicon'))

回答1:


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 _



回答2:


_ 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.




回答3:


_ is usually a macro/function from gettext, it means the argument is a localized string. this is not limited to Django or Python. in fact gettext is originally a package for C programs, ported to many other languages over the years.



来源:https://stackoverflow.com/questions/1962287/what-does-do-in-django-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!