After running a docker image of my django app, I notice that downloading files is no longer available. The only thing I get is a copy of the website page I am currently on and not the requested file.
Locally, it is working fine.
Here is how my code is organized :
In main/views.py :
path_to_report = f"media/Reports/{request.user.username}/{request.user.username}{now.hour}{now.minute}{now.second}.txt"
return render(request, "main/result.html", {"dic_files": dic_files, "nbr":len(files), "dic_small":dic_small, "dic_projects":dic_projects, "path_to_report":f"/app/{path_to_report}"})
In main/result.html
<a href=/{{path_to_report}} download>
<button name="rapport" value="rapport"> Télécharger votre rapport</button>
</a>
Here is my dockerfile :
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.8
# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True
EXPOSE 8000
## api-transport-https installation
RUN apt-get install apt-transport-https ca-certificates gnupg
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Install production dependencies.
RUN pip3 install --upgrade pip setuptools wheel
RUN pip3 install -r requirements.txt
RUN python manage.py makemigrations
RUN python manage.py migrate
RUN python manage.py collectstatic --no-input
ENTRYPOINT ["gunicorn", "myteam.wsgi:application", "--bind=0.0.0.0:8000", "--workers=4", "--timeout=300", "--log-level=debug"]
CodePudding user response:
In your main/views.py, try replacing:
"path_to_report":f"/app/{path_to_report}"
with :
"path_to_report":path_to_report