在运行了我的Django应用程序的docker图像后,我注意到不再提供下载文件的功能.我得到的唯一东西是我目前所在的网站页面的副本,而不是所请求的文件.
在当地,它运行得很好.
下面是我的代码的组织方式:
在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}"})
在main/result.html年内
<a href=/{{path_to_report}} download>
<button class="btn btn-success" name="rapport" value="rapport"> Télécharger votre rapport</button>
</a>
以下是我的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"]