我正在使用 Flask-Security,一切正常,除了电子邮件确认链接。显然,当用户注册时,他会收到一封电子邮件,其中包含确认电子邮件的链接,因此当他/她单击该链接时,我的应用程序会给出 SQL 日期时间错误。确切的错误是:
sqlalchemy.exc.StatementError
StatementError: SQLite DateTime type only accepts Python datetime and date objects as input. (original cause:
TypeError: SQLite DateTime type only accepts Python datetime and date objects as input.)
'UPDATE user SET confirmed_at=?, last_login_at=?, current_login_at=?, last_login_ip=?, current_login_ip=?,
login_count=? WHERE user.id = ?' [{u'user_id': 1, 'confirmed_at': datetime.datetime(2014, 5, 31, 23, 46, 38, 559513),
'login_count': 1, 'last_login_ip': '127.0.0.1', 'last_login_at': datetime.datetime(2014, 5, 31, 23, 46, 38, 557310),
'current_login_at': datetime.datetime(2014, 5, 31, 23, 46, 38, 557310), 'current_login_ip': '127.0.0.1'}]
因此,想问我应该怎么做才能克服这个错误。
这是我的models.py:
from app import db
from flask.ext.security import UserMixin, RoleMixin
#association table that stores users and their roles
roles_users = db.Table('roles_users',
db.Column('user_id', db.Integer(), db.ForeignKey('user.id')),
db.Column('role_id', db.Integer(), db.ForeignKey('role.id')))
#orm table that stores information on roles
class Role(db.Model, RoleMixin):
id = db.Column(db.Integer(), primary_key=True)
name = db.Column(db.String(80), unique=True)
description = db.Column(db.String(255))
class User(db.Model, UserMixin):
"""a class that used to create ORM Database and
objects related to the class"""
id = db.Column(db.Integer, primary_key = True)
email = db.Column(db.String(255), unique = True)
password = db.Column(db.String(255))
active = db.Column(db.Boolean())
roles = db.relationship('Role', secondary=roles_users,
backref=db.backref('users', lazy='dynamic'))
# Extra fields for Flask-Security
name = db.Column(db.String(255))
surname = db.Column(db.String(255))
birth_date = db.Column(db.Date)
# SECURITY_CONFIRMABLE
confirmed_at = db.Column(db.DateTime())
# SECURITY_TRACKABLE
last_login_at = db.Column(db.DateTime())
current_login_at = db.Column(db.DateTime())
last_login_ip = db.Column(db.String(40))
current_login_ip = db.Column(db.DateTime())
login_count = db.Column(db.Integer(6))
def is_authenticated(self):
return True
def is_active(self):
return True
def is_anonymous(self):
return False
def get_id(self):
return unicode(self.id)
def set_password():
pass
def check_password():
pass
def __repr__(self):
return '<User %r>' % (self.username)