Python Forum
How can users store data temporarily in flask app? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: How can users store data temporarily in flask app? (/thread-36698.html)



How can users store data temporarily in flask app? - darktitan - Mar-20-2022

Hi
Im wondering how users in my app can store data temporarily?

Right now im using lists who shows some data the user inputs. It works kind off when the app is used locally but its starts not to show every thing etc in the lists when the app is used on heroku. And i realized that i cant use lists like that if multiple users us the app. Do any one have any ideas how i can do it?


RE: How can users store data temporarily in flask app? - ndc85430 - Mar-21-2022

What kind of data? What does temporarily mean?
How do you need to access it? Web apps often use a database for storing data. Heroku at least gives you access to Postgres, but others may be available.


RE: How can users store data temporarily in flask app? - darktitan - Mar-21-2022

(Mar-21-2022, 12:43 PM)ndc85430 Wrote: What kind of data? What does temporarily mean?
How do you need to access it? Web apps often use a database for storing data. Heroku at least gives you access to Postgres, but others may be available.

Its just small text sequences my app generat. With temporary i mean that the data should be removed lets say after one hour or logout. And it should only be visible for the user who generated it. Yes i know heroku use postgres i use it for user accounts.

The data can look like this

W3.1
W3.2
W3.3
W3.sc


RE: How can users store data temporarily in flask app? - ndc85430 - Mar-21-2022

Could you just store the data in memory then? Is there a downside to doing that?


RE: How can users store data temporarily in flask app? - darktitan - Mar-21-2022

(Mar-21-2022, 05:42 PM)ndc85430 Wrote: Could you just store the data in memory then? Is there a downside to doing that?

Thats what i do now. I use list for it. But some times not all input gets added to the list and when i spam refresh in the browser it shows the missing inputs but not the first inputs in the table. I know its strange. But this does not happen when i run the app locally on my computer. So i have no idea what to do to get it to work on heroku.


RE: How can users store data temporarily in flask app? - ndc85430 - Mar-21-2022

You haven't shown any code, so we'd have to guess at what the problem could be, wouldn't we?


RE: How can users store data temporarily in flask app? - darktitan - Mar-21-2022

(Mar-21-2022, 06:07 PM)ndc85430 Wrote: You haven't shown any code, so we'd have to guess at what the problem could be, wouldn't we?

No its just lots of code so i will try to minimize it

my list that i use to store the data.they are global
sample_data1=[]
sample_data2=[]
sample_data3=[]
this is some of the code that generate the data and adds it to the lists
for parts in range(partfran-1, parttill):
	print('{}{}{}{}{}\n'.format(name, bindning, parts+1, bindning,  parts+1))
	sample_data1.append('{}{}{}{}{}\n'.format(name, bindning, parts+1, bindning,  parts+1))
sample_data2.append('{}\n'.format(name))  


this code shows whats in the sample_data2 list.
@app.route("/slutsteg1", methods=["GET", "POST"])
@roles_required(['admin', 'user'])
def sistasteg1():
    mylist = sample_data2
    my_list = []
    
    for (i, item) in enumerate(mylist, start=1):
         my_list.append({"ID":i, "Märkning":item})

    return render_template("slutsteg1.html",my_list=my_list)  


this shows whats in my_list list in a table
Quote: {% for item in my_list %}
<tr>
<td style="text-align:center">{{ item.ID }}</td>
<td style="text-align:center">{{ item.Märkning }}</td>
</tr>
{% endfor %}