正确使用'flask peewee'中的auth.login_required

时间:2013-08-17 17:01:07

标签: python flask peewee

我有自定义管理类。使用HOw auth.login_required ...简单地使用@ auth.login_required作为装饰器没有帮助。我的代码段

my_model.py

class User(db.Model, BaseUser):
    username = CharField()
    password = CharField()
    email = CharField(default='')
    active = BooleanField(default=False)
    #...other fields

    def is_active(self):
        return self.active

    def is_anonymous(self):
        return False

    def is_authenticated(self):
        return True

    def __unicode__(self):
        return self.username

auth.py

class CustomAuth(Auth):
    def get_user_model(self):
        return User

    def get_model_admin(self):
        return UserAdmin

# instantiate custom auth
auth = CustomAuth(app, db, user_model=User) 

usuage

@some_url.route('/some_url')
@auth.login_required # ITS NOT WORKIN
def some_url():
    return "test url"

1 个答案:

答案 0 :(得分:0)

试试这个

@some_url.route('/some_url')
@auth.login_required # ITS NOT WORKIN
def some_url():
    user = auth.get_logged_in_user()
    return "test url"