django asgi/channels not deployment failing

48 views Asked by At

I currently have a Django ASGI project that runs well locally, but when I try to deploy it on Render or Railway, I encounter an error.

Below are my build script (build.sh), Procfile, and relevant sections:

My Asgi.py

import django
import os
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

django.setup()

from chat.routing import websocket_urlpatterns

from hometweet.routing import websocket_urlpatterns
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "root.settings")

django_asgi_app = get_asgi_application()

application = ProtocolTypeRouter(
    {
    "http": django_asgi_app,
    "websocket": AllowedHostsOriginValidator(
    AuthMiddlewareStack(URLRouter(websocket_urlpatterns))
    ),
    }
)

**Build Script (`build.sh`):**
#!/bin/bash

# Upgrade pip and setuptools
pip install --upgrade pip
pip install --upgrade setuptools

# Install Dependencies
pip install -r requirements.txt

# Run Migrations
python manage.py makemigrations user
python manage.py makemigrations hometweet
python manage.py makemigrations profiles
python manage.py makemigrations groupapp
python manage.py migrate

**Procfile**
gunicorn root.asgi:application -k uvicorn.workers.UvicornWorker. 

I've tried various start commands, including:

  • web: daphne -u /tmp/daphne.sock yourproject.asgi:application
  • web: gunicorn root.wsgi:application
  • gunicorn root.wsgi:application
  • web: gunicorn root.asgi:application
  • gunicorn root.asgi:application
  • web: gunicorn root.asgi:application -k uvicorn.workers.UvicornWorker

The last command is currently giving me a server error when attempting to access the page. is there something i need to change or add please. Please someone should help me out on how i can deploy it either on render or railway. thanks

0

There are 0 answers