1

我有一个自定义管理类。如何使用 auth.login_required...仅使用 @auth.login_required 作为装饰器没有帮助。我的代码片段

我的模型.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

授权文件

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) 

用法

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

1 回答 1

0

尝试这个

@some_url.route('/some_url')
@auth.login_required # ITS NOT WORKIN
def some_url():
    user = auth.get_logged_in_user()
    return "test url"
于 2013-10-05T05:12:23.950 回答