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?
The whole file I am looking at is: 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). This approach is used not only in Python but also in other programming languages / projects that require translated strings.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With