为什么在docker镜像中运行Django应用程序后,下载属性不再有效



在运行我的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"]

main/views.py中,尝试替换:

"path_to_report":f"/app/{path_to_report}"

带有:

"path_to_report":path_to_report

最新更新