Heroku找不到生成的文件



我有一个生成PDF文件的Django项目。下面是相应的代码:

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')

当我运行本地服务器并运行我的函数时,PDF保存在我的模板目录中。然而,在Heroku部署后,生成PDF PDF没有找到。我试着在bash中寻找它,但是它就是不存在。

怎么了?

这是错误信息:

[Errno 2] No such file or directory: '/app/templates/texput.pdf' -> '/app/media/pdf/myfirstcv.pdf'

有多种可能性:

  • PDF根本没有创建(即使它在本地服务器上工作)
    • 是否有办法检查文件是否在Heroku上创建?
  • PDF不命名为texput.pdf(即使名称在本地服务器上始终相同)
    • 我认为名称将总是相同的。
  • PDF没有按预期保存到模板文件夹中
    • 是否有办法检查文件是否保存在其他地方?

上次我检查时,您可以在Heroku机器上创建或生成文件,但在创建新的request(I)之后,它们将消失。E:如果你访问一个新的页面)。

免责声明这是我通过观察和测试得出的理解。

我建议你在尝试检索文件之前设置一个storage区域,如cloudary, AWS, Firebase等来存储文件。

最新更新