0

I would like to upload a file with data to Django, and use django's forms to validate the data.

My idea was to have two views:

  1. A form where the user selecte the upload file The file is uploaded to thy server
  2. When the file successfully we are redirected to a from processing view, where the data in the file is used to populate the form and process it.

According to this anser, you can't POST data with a redirect: Django: How do I redirect a post and pass on the post data

Is there a common pattern to achieve this sort of behaviour?

I could easily use the initail kwarg to the form / view to populate it but the user needs to submit the from from the second page. I would like to process the form from the get request without the user needing to manually submit the initial form (a redirect with POST essentially).

(If this can be cleanly achived with generic class based views, all the better).

Community
  • 1
  • 1
wobbily_col
  • 11,390
  • 12
  • 62
  • 86

1 Answers1

1

The simple way to do this would be to extract the data in the first view and store it in the session. The second view would then simply retrieve the data from the session and use it to populate the form.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • Thats a decent option, it just seems a bit wrong from a separation of concerns point of view. I would prefer the excel parsing to be done by the second view. I'll go with that unless someone suggests something better. – wobbily_col Sep 06 '15 at 19:48