0

I have created an app in Django (which runs in a Docker Container) that takes several inputs from a form. Based on the inputs a python scripts runs that creates a PDF file in a certain folder.

It works fine when I save the PDF in a folder within the app ('static/createdpdf'). However, I would like to be able to save to a directory on my local machine.

When I try this I get an Exception File Not Found.

I tried to add a function that saves it in my app first and then moves it to my local machine folder, but that doesn't work either.

Any suggestions?

import shutil
import os

def movefiles():
    filename = 'Testinvoice.PDF'
    src_path = 'static/images/'
    dst_path = '/Users/jeandelisseen/Desktop/Testfolder/')
    filestring_src = os.path.join(src_path, filename)
    filestring_dst = os.path.join(dst_path, filename)
    shutil.move(filestring_src, filestring_dst)

My Docker File and Docker-Compose files are still pretty basic:

# Pull base image
FROM python:3.10

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Install dependencies
COPY Pipfile Pipfile.lock /code/

RUN pip install pipenv && pipenv install --system
# Copy project
COPY . /code/
version: '3.10'

services:
  web:
    build: .
    command: python /code/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - 8000:8000
    depends_on:
      - db
    environment:
      - "DJANGO_SECRET_KEY=django-insecure-1x^ewotre&i72i-+is3io%8yq8kzf1!r1vc4$$=yx7+^9vcpc2@"
      - "DJANGO_DEBUG=True"
  db:
    image: postgres:11
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    environment:
      - "POSTGRES_HOST_AUTH_METHOD=trust"

volumes:
  postgres_data:
  • You can store those files in `code` directory inside of the docker. This directory is shared between docker container and your local machine, hence you should be able to see the pdf files inside the local machine directory where the source codes reside. – ruddra May 11 '23 at 07:31

0 Answers0