Can someone please explain to me the difference between these two blocks of code. The first one works while the latter throws the error which I’ve indicated in the title.
def login_required(method):
@functools.wraps(method)
def wrapper(*args, **kwargs):
if 'username' in flask.session:
return method(*args, **kwargs)
else:
flask.flash("A login is required to see the page!")
return flask.redirect(flask.url_for('index'))
return wrapper
AND
def login_required(method):
@functools.wraps(method)
def wrapper(*args,**kwargs):
if "username" in flask.session:
return method(*args,**kwargs)
else:
flask.flash("A login is required to see the page!")
return flask.redirect(flask.url_for('index'))
return wrapper
In the first code sample, you correctly return the
wrapperfunction at the end of thelogin_requiredfunction.In the second code sample you’ve got the
return wrapperinside thewrapperfunction itself. Just de-dent that last line and you should be all set.