1

我目前正在开发我的网站管理界面。但是,当我测试添加新用户时,我得到以下回溯:

Traceback (most recent call last):
  File "/home/cody/Documents/Flask/SUPRacing/flask/lib/python2.7/site-packages/flask/app.py", line 1701, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/cody/Documents/Flask/SUPRacing/flask/lib/python2.7/site-packages/flask/app.py", line 1689, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/cody/Documents/Flask/SUPRacing/flask/lib/python2.7/site-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/cody/Documents/Flask/SUPRacing/flask/lib/python2.7/site-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/cody/Documents/Flask/SUPRacing/flask/lib/python2.7/site-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/cody/Documents/Flask/SUPRacing/flask/lib/python2.7/site-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/cody/Documents/Flask/SUPRacing/flask/lib/python2.7/site-packages/flask_peewee/auth.py", line 170, in login
    form.password.data,
  File "/home/cody/Documents/Flask/SUPRacing/flask/lib/python2.7/site-packages/flask_peewee/auth.py", line 128, in authenticate
    if not user.check_password(password):
  File "/home/cody/Documents/Flask/SUPRacing/flask/lib/python2.7/site-packages/flask_peewee/auth.py", line 25, in check_password
    return check_password(password, self.password)
  File "/home/cody/Documents/Flask/SUPRacing/flask/lib/python2.7/site-packages/flask_peewee/utils.py", line 138, in check_password
    salt, hsh = enc_password.split('$', 1)
ValueError: need more than 1 value to unpack

这是我的程序的各个相关领域的代码:model.py

class User(db.Model):
    id = IntegerField(primary_key=True)
    username = CharField()
    password = CharField()
    email = CharField(120)
    admin = BooleanField(default=False)
    active = BooleanField(default=True)

    # Flask-Login integration
    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return self.id

    # Required for administrative interface
    def __unicode__(self):
        return self.username
    def __repr__(self):
        return '<User %r>' % (self.username)

应用程序.py

class UserView(ModelAdmin):
    columns = ('username', 'email', 'admin', 'active')
    filter_exclude = ('id', 'password')
    exclude = ('id')

我确定我遗漏了一些明显的东西,但我想我会发布它以防万一。如果我是,我在这里做错了什么?

这是我执行此操作时管理界面的一些屏幕截图。 截图来自 2014-05-21 12 04 05 截图来自 2014-05-21 12 04 20 截图来自 2014-05-21 12 04 44

4

1 回答 1

0

根据Flask-Pewee 文档,如果您定义了在您的情况下执行的自定义用户模型,则必须扩展 BaseUser 类。这将确保根据此代码将您的密码创建为 (salt,hash) 的元组

现在,您在此行收到错误

salt, hsh = enc_password.split('$', 1)

这是试图拆分从未存在的元组

因此,简短的回答是您的用户模型应定义为:

class User(db.Model, BaseUser):
于 2014-05-21T18:48:01.343 回答