简体   繁体   English

Django将文件从一个视图动作传递到另一个

[英]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.

相关问题 在Django中将列表从一个视图传递到另一个视图 - Pass lists from one view to another in Django 在Django中将数据从一个视图传递到另一个视图的正确方法? - Correct way to pass data from one view to another in django? 是否可以将httprequest参数从一个视图函数传递给Django中的另一个 - Is it possible to pass httprequest parameter from one view function to another in Django 如何在Django中将列表从一个视图传递到另一个视图? - How do I pass a list from one view to another in Django? Django-通过 <select>从一个视图到另一个视图形成POST数据 - Django - Pass a <select> form POST data from one view to another Django - 将 Session 变量从一个视图传递到另一个视图(“请求”未定义) - Django - Pass Session Variables From One View To Another ('request' is undefined) Django:如何将请求对象从一个视图传递到另一个视图? - Django: how to pass request object from one view to another? 如何将变量从一个视图传递到另一个视图并使用 Django 中最后一个视图的 URL 进行渲染? - How do I pass variables from one view to another and render with the last view's URL in Django? 如何使用会话将字典从Django的一个视图传递到另一个视图? - How do I pass a dictionary from one view to another in Django using session? 在Django视图中将Markdown从文件传递到模板 - Pass markdown from file to template in Django view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM