0

I'm very new to python flask development and I just finished my first web app. To put my python flask web app into a simple example, let's say that the web app requires you to login with a user ID and password (authenticated with LDAP). Once logged in, the web app allows you to input a number into a form and the input will be appended into a list in the back-end.

The problem right now is, let's say User A appends "100" to the list in the back-end. Now, when User B logs in from a different browser, he/she will see that the "100" is already appended to the list. How do I make my web app in such a way where User B will have an empty list when he logs in? So, I want the changes made by User A and User B to be specific to them only. Any tips/explanations on how to go about this would be greatly appreciated.

Rking14
  • 325
  • 2
  • 5
  • 17

1 Answers1

1

Your application requires a database. There is a simple database called SQLite3 and python has it in the standard library.

You can store user credentials in session of flask application like:

session['user'] = request.form['user']

That is, when user submits form with containing input with attribute name=user. You collect data from that form submitted, and store it in session.

And at beginning you can check if user is logged in with something like:

if session.get('user') is not None:
    ...

You can read more how to create SQLite3 database with flask here. But please, if you want to learn more, learn what are databases, tables, how to create tables and data in them, and how to query them for proper results of reading and writing.

Dinko Pehar
  • 5,454
  • 4
  • 23
  • 57