[Answered ]-Passing data from post form to FileResponde view

1👍

reverse() only returns the URL, but I think you rather want to do a redirect() to that view.

For passing the parameters you have several options:

  • GET parameters
  • Session
  • URL parameters

Let’s use GET parameters, which I would suggest:

from urllib.parse import urlencode

...
def submitForm(request):
    ...
    response = redirect('pdf')
    params = { state' : state, 'date_start: date_start, 'date_end': date_end}
    response['Location'] += f'?{urlencode(params)}'
    return response

Then in your PDF view you need to parse the GET parameters:

def createPdf(request):
    date_start = request.GET.get("date_start")
    ...

Note that you may also need to convert your dates into string and back for the query, which I ignored here.

Leave a comment