gpt4 book ai didi

django - 为什么在 docker 镜像中运行我的 Django 应用程序后,下载属性不再起作用?

转载 作者:行者123 更新时间:2023-12-02 01:30:04 25 4
gpt4 key购买 nike

运行我的 django 应用程序的 docker 镜像后,我注意到下载文件不再可用。我得到的唯一的东西是我当前所在的网站页面的副本,而不是请求的文件。

在本地,它运行良好。

这是我的代码的组织方式:

ma​​in/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}"})

ma​​in/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"]

最佳答案

在您的ma​​in/views.py中,尝试替换:

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

与:

"path_to_report":path_to_report

关于django - 为什么在 docker 镜像中运行我的 Django 应用程序后,下载属性不再起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73540902/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com