Asgi:Daphne Django问题

yb3bgrhw  于 2023-10-21  发布在  Go
关注(0)|答案(1)|浏览(120)

嘿,我在我的项目中有错误,它是一种有线错误,因为代码在本地工作得很好,但当我在铁路上部署它时,它不工作,我安装了通道[达芙妮]并创建了网络套接字,它工作得很好,但在部署时它给出了这个错误

2023-10-04 19:10:30,487 INFO     /app/.env not found - if you're not configuring your environment separately, check this.
Traceback (most recent call last):
File "/opt/venv/bin/daphne", line 8, in <module>
sys.exit(CommandLineInterface.entrypoint())
File "/opt/venv/lib/python3.10/site-packages/daphne/cli.py", line 171, in entrypoint
cls().run(sys.argv[1:])
File "/opt/venv/lib/python3.10/site-packages/daphne/cli.py", line 233, in run
application = import_by_path(args.application)
File "/opt/venv/lib/python3.10/site-packages/daphne/utils.py", line 12, in import_by_path
target = importlib.import_module(module_path)
File "/root/.nix-profile/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/app/./project/asgi.py", line 1, in <module>
import notification.routing
File "/app/notification/routing.py", line 2, in <module>
from notification.consumer import NotificationConsumer
File "/app/notification/consumer.py", line 7, in <module>
from notification.models import Notification
File "/app/notification/models.py", line 3, in <module>
from posts.models import PublishedPost
File "/app/posts/models.py", line 2, in <module>
from django.contrib.auth.models import User
File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/opt/venv/lib/python3.10/site-packages/django/db/models/base.py", line 127, in __new__
app_config = apps.get_containing_app_config(module)
File "/opt/venv/lib/python3.10/site-packages/django/apps/registry.py", line 260, in get_containing_app_config
self.check_apps_ready()
File "/opt/venv/lib/python3.10/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.

我试图检查我的软件包,如果有不同的req.txt,但它都是相同的,并创建了一个runtime.txt,我不知道在哪里检查错误,因为它的工作正常本地

qacovj5a

qacovj5a1#

快速解答

我看不到您的代码,但在从WSGI转到ASGI时,我也遇到过类似的导入问题。我认为这可以解决你如何做你的进口

from django.core.asgi import get_asgi_application

# Initialize Django ASGI application early to ensure the AppRegistry
# is populated before importing code that may import ORM models.
django_asgi_app = get_asgi_application()

from posts.models import PublishedPost
from ... import ...
from ... import ...

旁注

一般来说,我建议使用uvicorn和gunicorn超过达芙妮的ASGI应用程序。它们更轻量级,在我看来,比django的默认对应部分更健壮。

相关问题