Answer the question
In order to leave comments, you need to log in
How to iterate over data from a Flask-MySQL database?
Good afternoon, I am creating a login form on the site, I use Flask-MySQL .
How to make iteration of data from the database using this library?
Or all the same advise to use SQLAlchemy ?
I also heard about Flask-security , but I really don't want to use it.
The code:
@app.route('/test', methods = ['GET','POST'])
def test():
if request.method == 'POST':
user = request.form['user']
key = request.form['pass']
cur.execute('SELECT * FROM `user`')
usr = cur.fetchall()
for us in usr:
if user and key == us:
return redirect('/admin')
else:
return redirect('/404')
return render_template('pages/test.html')
Answer the question
In order to leave comments, you need to log in
Or would you still recommend using SQLAlchemy?
SELECT * FROM `user`
took all the users in the line there, and then you compare whether there is such a user or not. And there will be 100500 billion users? So what to do? Every time twist such horror. cur.execute("""select id from user where login=%s and pass=%s""", (login, passw))
If cur.fetchone().get('id'):
return redirect(url_for('admin'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question