[英]Django Pass file from one view action to another
I have a view with two actions. 我有两个观点。 First one renders FileInput for csv.
第一个呈现csv的FileInput。 After submit, I read csv header and render the template for second action with dropdown containing header items.
提交后,我读取了csv标头,并通过包含标头项目的下拉菜单呈现了第二个操作的模板。 After dropdown items are selected and submitted, I want to read csv file, saving selected columns to db in second action.
选择并提交下拉菜单项后,我想读取csv文件,并在第二个操作中将选定的列保存到db。 How can I pass file from one action to another?
如何将文件从一个动作传递到另一个动作?
Short answer: you can't. 简短的答案:您不能。 The solution here is to store the file somewhere and save the file path in session, then read the path back from session and re-read the file.
此处的解决方案是将文件存储在某个位置,然后将文件路径保存在会话中,然后从会话中读取路径并重新读取文件。
Also, having the same view doing so many things is possibly not the best design, but YMMV... 同样,以相同的观点做很多事情可能不是最好的设计,但是YMMV ...
腌制该文件并在视图中的会话中存储腌制详细信息,并在另一个视图中从会话中访问腌制详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.