When I try to publish my project with daphne, which runs smoothly while running on the development server, I get the following output.
(venv) C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog> daphne -b 0.0.0.0:8000 myblog.asgi:application
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\venv\Scripts\daphne.exe\__main__.py", line 7, in <module>
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\venv\Lib\site-packages\daphne\cli.py", line 171, in entrypoint
cls().run(sys.argv[1:])
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\venv\Lib\site-packages\daphne\cli.py", line 233, in run
application = import_by_path(args.application)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\venv\Lib\site-packages\daphne\utils.py", line 17, in import_by_path
target = importlib.import_module(module_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Fahri\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\myblog\asgi.py", line 8, in <module>
from socketchat.routing import websocket_urlpatterns
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\socketchat\routing.py", line 4, in <module>
from socketchat import consumers
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\socketchat\consumers.py", line 7, in <module>
from socketchat.models import Message, ConversationSocket
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\socketchat\models.py", line 3, in <module>
from userapp.models import User
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\userapp\models.py", line 2, in <module>
from django.contrib.auth.models import AbstractUser
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\venv\Lib\site-packages\django\contrib\auth\models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\venv\Lib\site-packages\django\contrib\auth\base_user.py", line 59, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\venv\Lib\site-packages\django\db\models\base.py", line 129, in __new__
app_config = apps.get_containing_app_config(module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\venv\Lib\site-packages\django\apps\registry.py", line 260, in get_containing_app_config
self.check_apps_ready()
File "C:\Users\Fahri\Desktop\Django Projects\My Examples\myblog\venv\Lib\site-packages\django\apps\registry.py", line 138, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
here is my installed apps
INSTALLED_APPS = [
# 3rd party apps
'daphne',
'rest_framework',
'channels',
'psycopg',
# my apps
'userapp',
'blogs',
'pages',
'socketchat',
# Django apps
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sitemaps',
]
my asgi.py file;
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myblog.settings")
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application
from socketchat.routing import websocket_urlpatterns
application = ProtocolTypeRouter(
{
"http": get_asgi_application(),
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(URLRouter(websocket_urlpatterns))
),
}
)
What I have difficulty understanding is that everything is normal on the development server, but when I want to run it with daphne, it says that the applications are not installed. By the way forgive me if my English is bad.