Levman5
@Levman5
print(“Hello World!”)

Ошибка при запуске django с daphe?

Привет, вот такую ошибку получаю при запуске django через daphne -p 8001 climbing_tinder.asgi:application:
Traceback (most recent call last):
  File "/root/climbing_tinder/.venv/bin/daphne", line 8, in <module>
    sys.exit(CommandLineInterface.entrypoint())
  File "/root/climbing_tinder/.venv/lib/python3.9/site-packages/daphne/cli.py", line 171, in entrypoint
    cls().run(sys.argv[1:])
  File "/root/climbing_tinder/.venv/lib/python3.9/site-packages/daphne/cli.py", line 233, in run
    application = import_by_path(args.application)
  File "/root/climbing_tinder/.venv/lib/python3.9/site-packages/daphne/utils.py", line 17, in import_by_path
    target = importlib.import_module(module_path)
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/root/climbing_tinder/./climbing_tinder/asgi.py", line 5, in <module>
    from finder import consumers
  File "/root/climbing_tinder/./finder/consumers.py", line 4, in <module>
    from finder.models import Notification
  File "/root/climbing_tinder/./finder/models.py", line 2, in <module>
    from files.models import Image
  File "/root/climbing_tinder/./files/models.py", line 4, in <module>
    class Image(models.Model):
  File "/root/climbing_tinder/.venv/lib/python3.9/site-packages/django/db/models/base.py", line 129, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/root/climbing_tinder/.venv/lib/python3.9/site-packages/django/apps/registry.py", line 260, in get_containing_app_config
    self.check_apps_ready()
  File "/root/climbing_tinder/.venv/lib/python3.9/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.


Из-за чего это может быть?
asgi.py


import os
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from django.urls import path
from finder import consumers
import django
import logging

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

logger = logging.getLogger(__name__)

# Setup Django
django.setup()

application = ProtocolTypeRouter({
    "http": get_asgi_application(),
    "websocket": URLRouter([
        path("ws/notifications/", consumers.NotificationConsumer.as_asgi()),
    ])
})


И мои приложения:
INSTALLED_APPS = [
    'daphne',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'finder.apps.FinderConfig',
    'files.apps.FilesConfig',
    'rest_framework',
    'rest_framework.authtoken',
    'drf_spectacular',
    'cities.apps.CitiesConfig',
    'channels',
    'token_auth.apps.TokenAuthConfig',
    'legal.apps.LegalConfig',
]



Но обычный runserver с daphe работает:
climbing_tinder % python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
June 17, 2024 - 08:30:48
Django version 4.2.11, using settings 'climbing_tinder.settings'
Starting ASGI/Daphne version 4.1.2 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
  • Вопрос задан
  • 54 просмотра
Решения вопроса 1
Levman5
@Levman5 Автор вопроса
print(“Hello World!”)
Я изменил свой asgi.py на такой и всё заработало:
import os
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from django.urls import path


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'climbing_tinder.settings')
django_asgi_app = get_asgi_application()


from finder import consumers

application = ProtocolTypeRouter({
    "http": django_asgi_app,
    "websocket": URLRouter([
        path("ws/notifications/", consumers.NotificationConsumer.as_asgi()),
    ])
})
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы