Reputation: 346
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
Upvotes: 1
Views: 3823
Reputation: 5362
In the first code sample, you correctly return the wrapper
function at the end of the login_required
function.
In the second code sample you've got the return wrapper
inside the wrapper
function itself. Just de-dent that last line and you should be all set.
Upvotes: 2