我创建了应用程序,它生成包含一些内容的pdf文件。 用户填写表单后,将提交该表单,并在大约 10 秒后打开文件预览。 我想显示消息,用户应在点击“提交”后等待文件。 当我添加消息时,它会显示,但不早于下载开始,并且消息不可见(显示得太晚)。 实际上,为了显示消息,我需要注释行
return responce
我的看法:
def pdf_create(request):
if (request.method == 'POST'):
form = MsdsForm(request.POST)
messages.info(request, f'''Please wait for a file.''')
if (form.is_valid()):
cd = form.cleaned_data
# A LOT OF CODE AND THINGS HERE wchich create pdf
response = HttpResponse(pdf_output, content_type='application/pdf')
response['Content-Disposition'] = f"filename=some_file.pdf"
return response
else:
form = MsdsForm()
return render(request, 'msds_form.html',{'form':form})
我在谷歌上搜索了几个小时,没有找到简单的解决方案。 我省略了一些细节还是这不是简单的方法?
我不知道在这种情况下是否有必要,但我不使用模型。
除了javascript我没有找到任何其他解决方案。 我使用了隐藏文本的解决方案,我在here
找到了它