AppRegistryNotReady: The translation infrastructure cannot be initialized

后端 未结 4 974
我在风中等你
我在风中等你 2021-02-12 08:55

When I try to access to my app, I\'m getting the following error.

AppRegistryNotReady: The translation infrastructure cannot be initialized before the a

4条回答
  •  旧时难觅i
    2021-02-12 09:37

    This is an answer for the less clever ones (like me): Be sure to check the obvious: The error message says: ... Check that you don't make non-lazy gettext calls at import time. So, if you use django's translation in the verbose_name of a model field or on any other part that is evaluated at import time, you need to use the *_lazy version. If not, you'll end up with the error the OP had.

    I basically had:

    from django.db import models
    from django.utils.translation import gettext as _
    import datetime
    # other things
    
    class myModle(models.Model):
        date = models.DateField(_('Date'), default=datetime.date.today)
        # other defs. and things
    

    And got the same error as the OP, but my wsgi config was fine.

    All I had to do was replacing gettext with gettext_lazy (or ugettext with ugettext_lazy) and everything was fine.

提交回复
热议问题