Getting error when deploying the django channels project in railway

byteupaiPRO

7 months ago

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

0 Replies

7 months ago

please do not create duplicate posts or cross post


byteupaiPRO

7 months ago

sorry do you know solution of it


7 months ago

you need to use Daphne


byteupaiPRO

7 months ago

yes already using


7 months ago

that id doesnt bring me to a project


byteupaiPRO

7 months ago

wait I will send 9626ee7a-574c-4d61-a75c-2d65bf18c4a3


7 months ago

you arent


byteupaiPRO

7 months ago

how to use it?


byteupaiPRO

7 months ago

I have added it in my Procfile


byteupaiPRO

7 months ago

release: python manage.py migrate
worker: daphne -b 0.0.0.0 -p $PORT charity_pro.asgi:application


7 months ago

you are using a Dockerfile, Procfiles are irrelevant


byteupaiPRO

7 months ago

wait


byteupaiPRO

7 months ago

-


byteupaiPRO

7 months ago

check this


byteupaiPRO

7 months ago

docker file


7 months ago

please enclose that in a code block


byteupaiPRO

7 months 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"]

byteupaiPRO

7 months ago

sorry


7 months ago

you can edit discord messages lol


byteupaiPRO

7 months ago

brother please help its urgent


7 months 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


byteupaiPRO

7 months ago

not getting properly


byteupaiPRO

7 months ago

other functionality working perfectly just problem in chat module


7 months ago

please fix the two issues i had just brought up


byteupaiPRO

7 months ago

check now


7 months ago

send me your dockerfile


byteupaiPRO

7 months ago

yes


byteupaiPRO

7 months 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 daphne

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

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

byteupaiPRO

7 months ago

release: python manage.py migrate
worker: daphne -b 0.0.0.0 -p $PORT charity_pro.asgi:application

byteupaiPRO

7 months ago

Procfile


7 months ago

again, you are using a Dockerfile, the Procfile is totally irrelevant and unused


byteupaiPRO

7 months ago

so remove the procfile?


byteupaiPRO

7 months ago

and add CMD in dockerfile?


7 months ago

still 2 problems.

  • you are missing a CMD line

  • you are setting a start command in the service settings


byteupaiPRO

7 months ago

now I am adding CMD in dockerfile and remove the procfile


byteupaiPRO

7 months ago

okay?


byteupaiPRO

7 months ago

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"]

byteupaiPRO

7 months ago

still getting this error: Not Found: /ws/chat/2f2ceffd-d524-4f68-881d-7170ea620c37/


7 months 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


byteupaiPRO

7 months ago

brother can you guide me by filename


7 months ago

filename?


byteupaiPRO

7 months ago

removed start command from railway


7 months ago

what about it? you havent done that yet


byteupaiPRO

7 months ago

no


byteupaiPRO

7 months ago

there are many errors comming related to daphne


byteupaiPRO

7 months ago

after removing the start command from railway


7 months ago

send your dockerfile please


byteupaiPRO

7 months ago

yes


byteupaiPRO

7 months ago

```# Pull official base image
FROM python:3.12-slim

Set environment variables

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DJANGOSETTINGSMODULE charitypro.settings # Properly set DJANGOSETTINGS_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"]

```


byteupaiPRO

7 months ago

changed made by chatgpt guide


byteupaiPRO

7 months ago

now getting this error:

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.


7 months ago

this would be an application level issue


byteupaiPRO

7 months ago

can you help me with that?


byteupaiPRO

7 months ago

solved brother


byteupaiPRO

7 months ago

thank you so much


7 months ago

im glad you where able to solve, but please note we can't offer application level support


byteupaiPRO

7 months ago

yaa no issue


byteupaiPRO

7 months ago

amazing experience with railway


Getting error when deploying the django channels project in railway - Railway Help Station