Django 1.7 problem

665 views
Skip to first unread message

Andreas Kuhne

unread,
Dec 3, 2014, 8:36:03 PM12/3/14
to django...@googlegroups.com
I am trying to migrate our current website to django 1.7.

Currently we are using a plugin called django-dbgettext to get parts of our database translated (we are running in 10 different languages). The problem is that django-dbgettext starts by going through all of the models and does this before the translation framework is running. So I get an exception during startup that says:
"django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time."

The problem seems to be that the classes are loaded before the models are correctly loaded and the translation framework is running. All of the classes use ugettext_lazy, but the stack trace includes ugettext. 

I want to rewrite the django-dbgettext plugin so that it goes through the code AFTER the models are correctly loaded. I don't know how to do this however. Is there anyway of running code after django is fully initialized?

Django admin should do the same thing, it also has a autodiscover() function and I was wondering why this doesn't happen with django admin? Could this be a good place to start looking for a solution?

Regards,

Andréas

Carl Meyer

unread,
Dec 4, 2014, 12:40:51 AM12/4/14
to django...@googlegroups.com
Hi Andreas,

On 12/03/2014 01:34 PM, Andreas Kuhne wrote:
> I am trying to migrate our current website to django 1.7.
>
> Currently we are using a plugin called django-dbgettext to get parts of our
> database translated (we are running in 10 different languages). The problem
> is that django-dbgettext starts by going through all of the models and does
> this before the translation framework is running. So I get an exception
> during startup that says:
> "django.core.exceptions.AppRegistryNotReady: The translation infrastructure
> cannot be initialized before the apps registry is ready. Check that you
> don't make non-lazy gettext calls at import time."
>
> The problem seems to be that the classes are loaded before the models are
> correctly loaded and the translation framework is running. All of the
> classes use ugettext_lazy, but the stack trace includes ugettext.
>
> I want to rewrite the django-dbgettext plugin so that it goes through the
> code AFTER the models are correctly loaded. I don't know how to do this
> however. Is there anyway of running code after django is fully initialized?

Indeed there is! See
https://docs.djangoproject.com/en/dev/ref/applications/#django.apps.AppConfig.ready

> Django admin should do the same thing, it also has a autodiscover()
> function and I was wondering why this doesn't happen with django admin?
> Could this be a good place to start looking for a solution?

Yes, admin.autodiscover now runs in the admin's AppConfig.ready() in
Django 1.7, so that would have been a good place to start looking :-)

Carl

signature.asc

Andreas Kuhne

unread,
Dec 4, 2014, 9:51:59 AM12/4/14
to django...@googlegroups.com

Carl

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/547FAD59.5090809%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.

Thanks Carl,

With your help here I was able to fix this in less than an hour. Was really easy :-)

Regards,

Andréas

sarfaraz ahmed

unread,
Jan 7, 2015, 5:40:10 PM1/7/15
to django...@googlegroups.com
I believe i am too facing the same issue. But from above conversation I am not able to get solution of this issue. Could please help me. 

Regards,
Sarfaraz Ahmed

Andreas Kuhne

unread,
Jan 7, 2015, 7:29:50 PM1/7/15
to django...@googlegroups.com
Hi Sarfaraz,

Are you also having problems with the dbgettext plugin? Or is it with another plugin?

Regards,

Andréas

sarfaraz ahmed

unread,
Jan 7, 2015, 8:23:38 PM1/7/15
to django...@googlegroups.com
I have posted the entire issue in another post. After that I found your reply.


I m beginner in Django. I have configured Django/Python/ Apache/Mod_wsgi on EC2 Amazon Windows instance. I see the similar error. I am not using any pluggins. The project is attempt to make Django work on Apache... and it not working. 

Regards,
Sarfaraz Ahmed

Andreas Kuhne

unread,
Jan 7, 2015, 9:00:00 PM1/7/15
to django...@googlegroups.com
Ok,

What I did was modify how the dbgettext plugin loaded and changed the registrations of the models.

You shouldn't have this problem without the plugin. Can you get the server to run without apache? If you just use manage.py runserver?

Regards,

Andréas

Reply all
Reply to author
Forward
0 new messages