我目前正在尝试通过获取和调整flask-peewee
扩展中包含的示例应用程序的一部分来构建一个应用程序(代码here)。我现在可以注册并显示登录屏幕。当我输入不正确的登录凭据时,我会收到一条消息,指出登录凭据不正确(如预期的那样)。但是当我输入正确的登录凭据时,我会得到一个巨大的回溯,我无法从中找到答案。
通常我会查看方法或模板,看看有什么问题。然而,在这种情况下,几乎所有东西(方法和模板)都由 peewee 处理。
下面我将首先粘贴 Traceback,然后(根据评论中的要求)粘贴我目前拥有的几个文件。非常欢迎任何有关可能出错的信息!
追溯:
File "/Library/Python/2.7/site-packages/Flask-0.10-py2.7.egg/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/Library/Python/2.7/site-packages/Flask-0.10-py2.7.egg/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Library/Python/2.7/site-packages/Flask-0.10-py2.7.egg/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Library/Python/2.7/site-packages/Flask-0.10-py2.7.egg/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Python/2.7/site-packages/Flask-0.10-py2.7.egg/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Library/Python/2.7/site-packages/Flask-0.10-py2.7.egg/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Library/Python/2.7/site-packages/Flask-0.10-py2.7.egg/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/Library/Python/2.7/site-packages/Flask-0.10-py2.7.egg/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Library/Python/2.7/site-packages/flask_peewee/auth.py", line 170, in login
form.password.data,
File "/Library/Python/2.7/site-packages/flask_peewee/auth.py", line 128, in authenticate
if not user.check_password(password):
File "/Library/Python/2.7/site-packages/flask_peewee/auth.py", line 25, in check_password
return check_password(password, self.password)
File "/Library/Python/2.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
我现在拥有的文件是:
- 主文件
- 应用程序.py
- 授权文件
- 配置文件
- 模型.py
下面我把全部的内容贴上来,为了清楚起见可能会省略一些内容:
主文件
from app import app
from models import *
from views import *
if __name__ == '__main__':
app.run()
应用程序.py
from flask import Flask
from flask_peewee.db import Database
app = Flask(__name__)
app.config.from_object('config.Configuration')
db = Database(app)
授权文件
from flask_peewee.auth import Auth
from app import app, db
from models import User
auth = Auth(app, db, user_model=User)
配置文件
class Configuration(object):
DATABASE = {
'name': 'mydatabase.db',
'engine': 'peewee.SqliteDatabase',
'check_same_thread': False,
}
DEBUG = True
SECRET_KEY = 'shhhh'
模型.py
from datetime import datetime
from flask_peewee.auth import BaseUser
from peewee import CharField, BooleanField, ForeignKeyField, TextField, DateTimeField, IntegerField
from app import db
class User(db.Model, BaseUser):
username = CharField()
password = CharField()
name = CharField()
registered = DateTimeField(default=datetime.now())
active = BooleanField(default=False)