Python Flask working with wraps
You indented the return wrap
line too far, now your decorator returns a None
value. Unindent the last line:
def login_required(test): @wraps(test) def wrap(*args, **kwargs): if 'logged_in' in session: return test(*args, **kwargs) else: flash('You need to login first.') return redirect(url_for('log')) return wrap
The exception points to the @login_required
line because the next decorator, @app.route('/hello')
throws the exception as it is applied to the output of @login_required
. The AssertionError
exception is thrown explicitly because the route decorator was passed a None
value for the function.