R
Railway2mo ago
vayak_

Getting error when deploying the django channels project in railway

only chat application not work other functionality working perfectly frontend error: WebSocket encountered an error:
Chat socket closed unexpectedly: backend error: Not Found: /ws/chat/2f2ceffd-d524-4f68-881d-7170ea620c37/ all setup done perfectly but now stuck not getting the solution from anywhere
Solution:
you need to use Daphne
Jump to solution
38 Replies
Percy
Percy2mo ago
Project ID: 2f2ceffd-d524-4f68-881d-7170ea620c37
Brody
Brody2mo ago
please do not create duplicate posts or cross post
vayak_
vayak_OP2mo ago
sorry do you know solution of it
Solution
Brody
Brody2mo ago
you need to use Daphne
vayak_
vayak_OP2mo ago
yes already using
Brody
Brody2mo ago
that id doesnt bring me to a project
vayak_
vayak_OP2mo ago
wait I will send 9626ee7a-574c-4d61-a75c-2d65bf18c4a3
Brody
Brody2mo ago
you arent
vayak_
vayak_OP2mo ago
how to use it? I have added it in my Procfile release: python manage.py migrate worker: daphne -b 0.0.0.0 -p $PORT charity_pro.asgi:application
Brody
Brody2mo ago
you are using a Dockerfile, Procfiles are irrelevant
vayak_
vayak_OP2mo ago
wait - check this docker file
Brody
Brody2mo ago
please enclose that in a code block
vayak_
vayak_OP2mo ago
# Pull official base image
FROM python:3.12-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set working directory
WORKDIR /app

# Install dependencies
COPY requirements.txt /app/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Copy project
COPY . /app/

# Install gunicorn
RUN pip install gunicorn

# Collect static files
# RUN python manage.py collectstatic --noinput

# Expose the dynamic port (optional, but not necessary)
EXPOSE 8000

# Use the environment variable $PORT for deployment
CMD ["gunicorn", "-k", "daphne", "-b", "0.0.0.0:$PORT", "charity_pro.asgi:application"]
# Pull official base image
FROM python:3.12-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set working directory
WORKDIR /app

# Install dependencies
COPY requirements.txt /app/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Copy project
COPY . /app/

# Install gunicorn
RUN pip install gunicorn

# Collect static files
# RUN python manage.py collectstatic --noinput

# Expose the dynamic port (optional, but not necessary)
EXPOSE 8000

# Use the environment variable $PORT for deployment
CMD ["gunicorn", "-k", "daphne", "-b", "0.0.0.0:$PORT", "charity_pro.asgi:application"]
sorry
Brody
Brody2mo ago
you can edit discord messages lol
vayak_
vayak_OP2mo ago
brother please help its urgent
Brody
Brody2mo ago
2 problems. - you are overwriting that CMD line via the start command in the service settings. - you are using exec form for that CMD line
vayak_
vayak_OP2mo ago
not getting properly other functionality working perfectly just problem in chat module
Brody
Brody2mo ago
please fix the two issues i had just brought up
vayak_
vayak_OP2mo ago
check now
Brody
Brody2mo ago
send me your dockerfile
vayak_
vayak_OP2mo ago
yes
# Pull official base image
FROM python:3.12-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set working directory
WORKDIR /app

# Install dependencies
COPY requirements.txt /app/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Copy project
COPY . /app/

# Install gunicorn
RUN pip install gunicorn daphne

# Collect static files
# RUN python manage.py collectstatic --noinput

# Expose the dynamic port (optional, but not necessary)
EXPOSE 8000
# Pull official base image
FROM python:3.12-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set working directory
WORKDIR /app

# Install dependencies
COPY requirements.txt /app/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Copy project
COPY . /app/

# Install gunicorn
RUN pip install gunicorn daphne

# Collect static files
# RUN python manage.py collectstatic --noinput

# Expose the dynamic port (optional, but not necessary)
EXPOSE 8000
release: python manage.py migrate
worker: daphne -b 0.0.0.0 -p $PORT charity_pro.asgi:application
release: python manage.py migrate
worker: daphne -b 0.0.0.0 -p $PORT charity_pro.asgi:application
Procfile
Brody
Brody2mo ago
again, you are using a Dockerfile, the Procfile is totally irrelevant and unused
vayak_
vayak_OP2mo ago
so remove the procfile? and add CMD in dockerfile?
Brody
Brody2mo ago
still 2 problems. - you are missing a CMD line - you are setting a start command in the service settings
vayak_
vayak_OP2mo ago
now I am adding CMD in dockerfile and remove the procfile okay? so this is my dockerfile updated and removed procfile
# Pull official base image
FROM python:3.12-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set working directory
WORKDIR /app

# Install dependencies
COPY requirements.txt /app/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Copy project
COPY . /app/

# Install gunicorn
RUN pip install gunicorn daphne

# Collect static files
# RUN python manage.py collectstatic --noinput

# Expose the dynamic port (optional, but not necessary)
EXPOSE 8000

# Use the environment variable $PORT for deployment
CMD ["gunicorn", "-k", "daphne", "-b", "0.0.0.0:$PORT", "charity_pro.asgi:application"]
# Pull official base image
FROM python:3.12-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set working directory
WORKDIR /app

# Install dependencies
COPY requirements.txt /app/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Copy project
COPY . /app/

# Install gunicorn
RUN pip install gunicorn daphne

# Collect static files
# RUN python manage.py collectstatic --noinput

# Expose the dynamic port (optional, but not necessary)
EXPOSE 8000

# Use the environment variable $PORT for deployment
CMD ["gunicorn", "-k", "daphne", "-b", "0.0.0.0:$PORT", "charity_pro.asgi:application"]
still getting this error: Not Found: /ws/chat/2f2ceffd-d524-4f68-881d-7170ea620c37/
Brody
Brody2mo ago
2 problems. - you are overwriting that CMD line via the start command in the service settings. - you are using exec form for that CMD line
vayak_
vayak_OP2mo ago
brother can you guide me by filename
Brody
Brody2mo ago
filename?
vayak_
vayak_OP2mo ago
removed start command from railway
Brody
Brody2mo ago
what about it? you havent done that yet
vayak_
vayak_OP2mo ago
no there are many errors comming related to daphne after removing the start command from railway
Brody
Brody2mo ago
send your dockerfile please
vayak_
vayak_OP2mo ago
yes
# Pull official base image
FROM python:3.12-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE charity_pro.settings # Properly set DJANGO_SETTINGS_MODULE to point to your settings module

# Set working directory
WORKDIR /app

# Install dependencies
COPY requirements.txt /app/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Copy project files
COPY . /app/

# Install daphne (no need for gunicorn)
RUN pip install daphne

# Expose the dynamic port (optional)
EXPOSE 8000

# Use the environment variable $PORT for deployment
CMD ["sh", "-c", "daphne -b 0.0.0.0 -p $PORT charity_pro.asgi:application"]
# Pull official base image
FROM python:3.12-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE charity_pro.settings # Properly set DJANGO_SETTINGS_MODULE to point to your settings module

# Set working directory
WORKDIR /app

# Install dependencies
COPY requirements.txt /app/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Copy project files
COPY . /app/

# Install daphne (no need for gunicorn)
RUN pip install daphne

# Expose the dynamic port (optional)
EXPOSE 8000

# Use the environment variable $PORT for deployment
CMD ["sh", "-c", "daphne -b 0.0.0.0 -p $PORT charity_pro.asgi:application"]
changed made by chatgpt guide now getting this error: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Brody
Brody2mo ago
this would be an application level issue
vayak_
vayak_OP2mo ago
can you help me with that? solved brother thank you so much
Brody
Brody2mo ago
im glad you where able to solve, but please note we can't offer application level support
vayak_
vayak_OP2mo ago
yaa no issue
vayak_
vayak_OP2mo ago
amazing experience with railway
Want results from more Discord servers?
Add your server