简体   繁体   English

如何在 Django 视图中存储从 postgres 获取的大型数据集?

[英]How to store large fetched dataset from postgres in Django view?

When user open some Django view there is option to choose what data to load from postgres DB.当用户打开一些 Django 视图时,可以选择从 postgres DB 加载哪些数据。 After that click submit and process is started.之后单击提交并开始处理。 But when data is fetched and in the same view pressed reload, then all process starts from begining.但是当获取数据并在同一个视图中按下重新加载时,所有过程都会从头开始。 Fetched time is about ~10min (best solution to fetched once by opening view and after that just manupulate with data without fetced each reloading)获取时间约为 10 分钟(通过打开视图获取一次的最佳解决方案,之后只需使用数据进行操作,而不需要每次重新加载)

I want to load data once or by button.我想加载一次或按按钮加载数据。 But how to implement that i don't understand.但是如何实现我不明白。

The easier approach is to do this with two pages:更简单的方法是使用两个页面来执行此操作:

  • First page: User can choose to load the data第一页:用户可以选择加载数据
  • Second page: Loads the data and shows it第二页:加载数据并显示

If you want to do this on the same page you normally put a div on your page where the data should be loaded and then you need to use Javascript / AJAX to load and update your current page (or a part of it) based on user input like a clicked button.如果您想在同一页面上执行此操作,您通常会在页面上放置一个 div 来加载数据,然后您需要使用 Javascript / AJAX 根据用户加载和更新当前页面(或其中的一部分)像点击按钮一样输入。

There are multiple ways to implement this.有多种方法可以实现这一点。 Here are some examples:这里有些例子:

I would recommend HTMX, because it allows you to do this without having to write any JavaScript and it works great together with Django templates.我会推荐 HTMX,因为它允许您在不编写任何 JavaScript 的情况下执行此操作,并且它与 Django 模板一起工作得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM