我有一些问题:如何捕捉我生成的pdf文件任务.py并在重定向到主页并将下载链接放入此页面后自动开始下载?我的任务.py因为我在终端看到了结果。在
我的任务.py公司名称:
@shared_task
def html_to_pdf(ctx):
html_string = render_to_string('pdf_template.html', ctx)
html = HTML(string=html_string)
html.write_pdf('/tmp/report.pdf')
fs = FileSystemStorage('/tmp')
with fs.open('report.pdf') as pdf:
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] \
= 'attachment; filename="report.pdf"'
return response
我的视图.py公司名称:
^{pr2}$
您的芹菜任务执行超时,并返回响应(因此任务.延迟()). 当他们到达该页面时,任务很可能仍在生成PDF。如果你想运行这个任务然后等待,你可以这样做
然后,我要做的是找出一种方法来创建另一个端点来提供该文件,而不是将其作为响应对象提供。在
相关问题 更多 >
编程相关推荐