了解鹡鸰源代码

Understand Wagtail SourceCode

查看 Wagtail 源代码时:

class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
    title = models.CharField(
        verbose_name=_('title'),
        max_length=255,
        help_text=_("The page title as you'd like it to be seen by the public")
    )

    slug = models.SlugField(
        verbose_name=_('slug'),
        allow_unicode=True,
        max_length=255,
        help_text=_("The name of the page as it will appear in URLs")
    )

我不明白 _('title')_('slug'),谁能分享一些提示?

"_(...)" 函数将从文件顶部导入为:

from django.utils.translation import gettext_lazy as _

来自 Django 文档:

These functions store a lazy reference to the string – not the actual translation. The translation itself will be done when the string is used in a string context, such as in template rendering.

https://docs.djangoproject.com/en/3.2/topics/i18n/translation/#lazy-translation