Reputation: 135
This question will likely betray my inexperience in web development, so please let me know if I'm solving entirely the wrong problem.
I'm building a web application where users are asked to upload a data file. After uploading, the users are shown some aggregate statistics of the data contained in the file to help catch any errors. The user can then confirm this is the right data. Only then will the file will be stored somewhere on other people's computers in the cloud.
I Django, I have defined three views/templates:
The problem is that the file is uploaded in the Upload view/template; but I only want to determine the aggregate statistics on the Check page and store the file after the user has confirmed its aggregate statistics in the Check view/template. I'm not sure how I can pass the file (which will be an InMemoryUploadFile
object) from the Upload view to the Check view.
Perhaps I'm trying to solve this the wrong way and I should find out a way to do the Check on the same page as the Upload form.
Edit: I have a working solution that feels hacky and not like the right way. Since the data file contains text, I can read its contents and store it in a string. In the Upoad view, I can add this string to the session by storing it in request.session["file_contents"]
. This request
is then passed to the next view when I redirect
from the Upload view to the Check view.
Upvotes: 1
Views: 55
Reputation: 1295
I see your problem can be solved in two ways:
a) InMemoryUploadFile
will be deleted after your view (function)
returns something.
view_reciever
, where this file will be processed with your business logic, and saved on the cloud
and returned to a user as statistic for confirmation, whether it is good or not.b) Using Ajax
request:
view
which will only process your file
and return statistics
via ajax request
.ajax request
with this file, and it would save file in the cloud.do nothing (but userfriendly)
(it isn't stored on your cloud anyway).Upvotes: 1