-2

hlo, I have deployed a Django rest app in production. When I call a list API there is a pagination, and I am getting localhost for next page URL.

I am using GenericViewSet and LimitOffsetPagination for pagination. My app is running in docker container.And it is pointed to a specific domain. We can access it using domain name "https://abc.xyz.com". But I have used python manage.py runserver:0.0.0.0:8000(it's just for testing) CMD for running the server. Here is the image for more detail. I am calling an live hosted API to get a list from postman. In response data list contains pagination, which contains "http://localhost:8000/api/transaction/?limit=10&offset=10&ordering=-pk&purpose=1". for next page link instead of domain name.

I have hosted application using docker. Following is my docker file:

# Set the working directory
WORKDIR /app
# Copy requirements file
COPY requirements.txt .
# Install dependencies
RUN pip install --upgrade pip && pip install -r requirements.txt
# Copy project files
COPY . .
# Collect static files
RUN python manage.py collectstatic --noinput
# Run migrations
RUN python manage.py makemigrations
RUN python manage.py migrate
# Expose the port 8000
EXPOSE 8000
# Start the server
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

What should I do to get "https://abc.xyz.com/api/transaction/" instead of "http://localhost:8000/api/transaction/"

1 Answers1

0

You can use relative url in your html, something like this:

http://localhost:8000/nextpage/?page=2

to

<a href="/nextpage/?page=2" />

When you change to this, your url will be change to yourdomain/nextpage/?page2. So you can run your app in localhost or VM or in container without changing host or absolute url for one by one environment you set up in project.

Khanh Le Tran
  • 860
  • 4
  • 15