django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet with Django’s user database authentication from Apache

1,394 views
Skip to first unread message

Binoy U

unread,
Jan 28, 2019, 7:20:24 AM1/28/19
to Django users
Hello,

I have created a django project with only one application. I haven't made any changes in the application. Only added the application to the settings and updated static and media urls.

Migration is done and super user was created.

I have configured apache(version:2.4.29) and mod_wsgi(4.5.17) according to Authenticating against Django’s user database from Apache.

But getting the following error in apache error log.

Traceback (most recent call last):
  File "/home/User1/Documents/test/check_apache/check_apache/wsgi.py", line 13, in <module>
    from django.contrib.auth.handlers.modwsgi import check_password
  File "/home/User1/Documents/test/lib/python3.6/site-packages/django/contrib/auth/handlers/modwsgi.py", line 5, in <module>
    UserModel = auth.get_user_model()
  File "/home/User1/Documents/test/lib/python3.6/site-packages/django/contrib/auth/__init__.py", line 165, in get_user_model
    return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
  File "/home/User1/Documents/test/lib/python3.6/site-packages/django/apps/registry.py", line 197, in get_model
    self.check_apps_ready()
  File "/home/User1/Documents/test/lib/python3.6/site-packages/django/apps/registry.py", line 132, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")

Please find files below wsgi.py

import os
import mod_wsgi

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'check_apache.settings')
from django.contrib.auth.handlers.modwsgi import check_password
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Error is triggered from from django.contrib.auth.handlers.modwsgi import check_password.


apache config file 000-defaults.conf


Authentication is enabled on the media url. So I hope the apache configuration is working fine. I have create a github repository if you would like to check.

I got this issue from a bigger project with many application and other django modules. But I could still reproduce the same issue with this simple project. Can you please help me to resolve this issue, thanks in advance!

Simon Charette

unread,
Jan 28, 2019, 10:16:30 AM1/28/19
to Django users
Hello there,

That looks like a Django bug to me as auth.get_user_model() should only be performed
from within the check_password() function as it will certainly crash at the module level.

You should file a bug report so it gets addressed[0].

Best,
Simon

Simon Charette

unread,
Jan 28, 2019, 2:11:53 PM1/28/19
to Django users
Hello again :)

Someone pointed out to me that it might be a documentation issue that requires
that you import check_password only after calling get_wsgi_application().

For example, your wsgi.py module would look like

import os
import mod_wsgi

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'check_apache.settings')

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

from django.contrib.auth.handlers.modwsgi import check_password

In all cases a bug report should be filled to either adjust the documentation or the calls to
get_user_model() in django.contrib.auth.handlers.modwsgi.

Best,
Simon

Binoy U

unread,
Jan 29, 2019, 7:00:06 AM1/29/19
to Django users
Hello Simon,

Thank you for the reply. I have changed it as you mentioned and it's working now. I will raise an issue to update the documentation.

Gundla Kumar

unread,
Jan 29, 2019, 7:48:01 AM1/29/19
to django...@googlegroups.com
Hai,

Can you help me how to solve my problem, when launch project in my local, it gives error as "ImportError: No module named copy_reg" and "ImportError: No module named multiplearray"

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/276e126a-6093-42b2-b6ce-9db77b919027%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages