When FALSK implements Filter user function with blueprint hook, the browser reports an error: you have been redirected too many times.

problem description

I am currently learning this book through Flask Web. Now I have learned Chapter 8. When I implement the re-authentication using hook Filter users to another interface when the user does not confirm their identity, I find that as long as I log in with the registered account, 127.0.0.1 will redirect you too many times. This is a problem

.

the environmental background of the problems and what methods you have tried

I can"t even start cookie after cleaning up according to what I said on the Internet.

related codes

@auth.before_app_request  -sharp
def before_request():
 -sharp
    if current_user.is_authenticated() \
            and not current_user.confirmed \
            and request.endpoint \
            and request.blueprint[:5] != "auth." \
            and request.endpoint != "static":    
        return redirect(url_for("auth.unconfirmed"))

-sharp
@auth.route("/unconfirmed")
def unconfirmed():
    if current_user.is_anonymous or current_user.confirmed:
        return redirect(url_for("main.index"))
    return render_template("auth/unconfirmed.html")
:
F:\\flasky\project>python manage.py
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 170-786-910
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
2
127.0.0.1 - - [12/Nov/2018 16:15:23] "GET / HTTP/1.1" 302 -
2
127.0.0.1 - - [12/Nov/2018 16:15:23] "GET /auth/unconfirmed HTTP/1.1" 302 -
2
127.0.0.1 - - [12/Nov/2018 16:15:23] "GET /auth/unconfirmed HTTP/1.1" 302 -
2
127.0.0.1 - - [12/Nov/2018 16:15:23] "GET /auth/unconfirmed HTTP/1.1" 302 -
2
127.0.0.1 - - [12/Nov/2018 16:15:23] "GET /auth/unconfirmed HTTP/1.1" 302 -
2

seems to keep calling the function unconfirmed ()

.
Nov.12,2021

the best way is to first check whether the judgment condition is correct. 99% of this problem may be that the judgment condition is written incorrectly. Print the judgment condition and make it clear at a glance


I find that it is because there is something wrong with the sentence if current_user.is_anonymous or current_user.confirmed, and it should be written as if current_user.is_anonymous () or current_user.confirmed
because the type of current_user.is_anonymous is class. And the result is always true, so the result of the judgment statement will always be true, so main.index, will be executed, but because the hook function is set, the unconfirmed function will be called again, resulting in repeated execution. This should be due to the difference between the version of python used in the book and the one I use

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3d1fe-2c360.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3d1fe-2c360.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?