W
W
wolverine7772021-03-18 00:29:15
Flask
wolverine777, 2021-03-18 00:29:15

How to display that the user is not in the database?

Hello, I can't understand why the one elsethat tells the user that he is not in the database and sends him to the page does not work test.html(to be sure)

@app.route('/login', methods = ['GET','POST'])
def login():
    form = LoginForm()

    if form.validate_on_submit():

        user = User.query.filter_by(email=form.email.data).first()

        if user.check_password(form.password.data) and user is not None:

            login_user(user)
            flash('Logged in successfully!')

            next = request.args.get('next')

            if next == None or not next[0]=='/':
                next = url_for('welcome_user')

            return redirect(next)

        else:
            flash('You are not in database')
            return render_template('test.html')
    return render_template('login.html', form=form)


Login works, but if the data is incorrect - no ( test.htmldoes not transfer)

According to (my) logic, if the user is not None, he logs in normally, but if he is just None- he must fly over elseto test.html

What is the problem?

Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2021-03-18
@bacon

Well, first you need to check that the user is not None, and not call check_password on None

N
nullnull, 2021-03-19
@nullnull

It might work like this :)

else:
            flash('You are not in database')
            return redirect(url_for('test'))


...

@app.route('/test/', methods = ['GET','POST'])
def test():
     return render_template('test.html')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question