I have a Django project which generates a PDF file. This below is the corresponding code:
def createPDF(name):
current_path = os.path.dirname(os.path.dirname(__file__))
template = get_template(f'src.tex')
context = {
'content': name,
}
rendered_tpl = template.render(context).encode('utf-8')
process = subprocess.Popen(
['pdflatex', '-output-directory', f'{current_path}/templates'],
stdin=PIPE,
stdout=PIPE,
)
process.communicate(rendered_tpl)
Path(f'{current_path}/templates/texput.pdf').rename(f'{current_path}/media/pdf/myfirstcv.pdf')
When I run the local server and run my function the PDF is saved in my templates directory. However, after deploying on Heroku, and generating the PDF the PDF is not found. I tried to look for it in the bash, but it is just not there.
What is wrong?
This is the error message:
[Errno 2] No such file or directory: '/app/templates/texput.pdf' -> '/app/media/pdf/myfirstcv.pdf'
There are multiple possibilities:
- The PDF is not created at all (even if it works on localserver)
- Is there a way to check if the file is created on Heroku?
- The PDF is not named
texput.pdf
(even if the name is always the same on the localserver)- I assume the name is going to be always the same.
- The PDF is not saved into templates folder as expected
- Is there a way to check if a file was saved somewhere else?