Q
Q
Quattro1112019-10-07 15:16:32
Flask
Quattro111, 2019-10-07 15:16:32

Problem with adding data to an array in Flask, how to fix?

Good afternoon! The following problem occurred:
@app.route('/', methods=['GET','POST'])
def index():
if request.method == "POST":
login = request.form['login'] # I read the login that the user entered into the form and assign it to a variable.
There is the following fragment of the working code, I need to make the 'login' variable global or add it to some array. When I try to make a global login, it gives an error. If I create an array at the very beginning and internal functions add the login variable to it, then the output is again an empty array. What to do, how to live?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-10-07
@NeiroNx

There are sessions for this:

from flask import session
@app.route('/', methods=['GET','POST'])
def index():
    if request.method == "POST":
        session['login'] = request.form['login']

sessions are transmitted in encrypted form in a Cookie to the client

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question