Philippe Haumesser
Philippe Haumesser

Reputation: 647

decorator with current user is admin

I m trying to add a decorator like this

def requires_admin(f):
    def wrapper(f):
        @wraps(f)
        def wrapped(*args, **kwargs):
            #if not admin:
                flash('You are not authorize to this page')
            return f(*args, **kwargs)
        return wrapped
    return wrapper

My User model have this field: admin = db.Column(Boolean)

thanks

Upvotes: 0

Views: 210

Answers (1)

Dave W. Smith
Dave W. Smith

Reputation: 24956

Studying the implemention of login_required in flask_login might be useful here. A quick glance shows that your snippet uses an extra layer of wrapper, and a read of theirs shows some edge cases that you might want to consider.

Upvotes: 1

Related Questions