Django message about waiting for process

  Kiến thức lập trình

I created app, which generate pdf file with some content.
After filling form by user it is submitted and after about 10 seconds file preview is opening.
I want to show message that user should wait for file after hiting Submit.
When I add a meesage it shows but not earlier than download start and message it is not visible (it shows too late).
Actually to show the messege I need to comment line return responce

my view:

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

I searched google for couple of hours and didn’t find simple solution.
I omit some details or it isn’t simple way to do that?

LEAVE A COMMENT