matt hoover
matt hoover

Reputation: 346

Flask python assertion error: unimplemented method 'GET'

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

Answers (1)

apiguy
apiguy

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

Related Questions