简体   繁体   English

Django密码= models.CharField(_('password'),max_length = 128)

[英]Django password = models.CharField(_('password'), max_length=128)

What relevance does the underscore have before ('password') in this line? 下划线在此行之前(“密码”)有什么相关性?

password = models.CharField(_('password'), max_length=128)

I looked at the Django documentation and it states that the first parameter in the model field definition is a 'verbose name', however I cannot find what relevance the underscore has in this case? 我查看了Django文档,它指出模型字段定义中的第一个参数是“冗长的名称”,但是在这种情况下,我找不到下划线有什么相关性?

The whole file I am looking at is: https://github.com/django/django/blob/master/django/contrib/auth/models.py 我正在查看的整个文件是: https : //github.com/django/django/blob/master/django/contrib/auth/models.py

Thanks, Mark 谢谢马克

The underscore is a common way of denoting that this string is available for translation: 下划线是表示此字符串可用于翻译的一种常见方式:

 from django.utils.translation import ugettext_lazy as _

This means the string will show up in tools that gather these strings and substitute them for translated strings (see GNU gettext for example). 这意味着该字符串将显示在收集这些字符串并将其替换为转换后的字符串的工具中(例如,请参见GNU gettext )。 This approach is used not only in Python but also in other programming languages / projects that require translated strings. 这种方法不仅在Python中使用,还在需要翻译字符串的其他编程语言/项目中使用。

If you were to change the language of your Django website it would know to display a different string instead of 'password' (depending on which translations are available, otherwise it'll default back to this English string). 如果您要更改Django网站的语言,它将知道显示一个不同的字符串而不是'password' (取决于可用的翻译,否则默认情况下将返回此英语字符串)。

Underscore might be for localization/translation. 下划线可能用于本地化/翻译。 Check the imports. 检查进口。 ex. 例如

from django.utils.translation import ugettext_lazy as _

In this link https://github.com/django/django/blob/master/django/contrib/auth/models.py look for line containing below import 在此链接中https://github.com/django/django/blob/master/django/contrib/auth/models.py查找包含以下import的行

from django.utils.translation import ugettext_lazy as _

For international character set (Unicode) support, ugettext().You can use ugettext_lazy() as the default translation method for a particular file. 对于国际字符集(Unicode)支持,使用ugettext()。您可以将ugettext_lazy()用作特定文件的默认翻译方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM