我正在为电子商务网站编写注册/登录系统,并使用 flask-security ( http://pythonhosted.org/Flask-Security/ ) 来处理注册功能。部分基本设置需要以下 signup.py 模块:
from flask.ext.security import SQLAlchemyUserDatastore, Security
from app.models import User, Role
from app import app, db
# Setup Flask Security
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore)
然后我必须将 user_datastore 和安全对象导入到我的 views.py 模块中,如下所示:
from app.signup import user_datastore, security
问题是,一旦我将上述导入语句包含到我的视图模块中,我的整个应用程序就会崩溃,并且当我尝试运行我的单元或行为测试时出现以下回溯错误(为便于阅读而编辑)
======================================================================
ERROR: Failure: AttributeError ('_FakeSignal' object has no attribute 'connect_via')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose/loader.py", line 413, in loadTestsFromName
addr.filename, addr.module)
File "/Library/Python/2.7/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Library/Python/2.7/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/faiyamrahman/programming/Python/WebApps/NibsNWhiskeyFull/tests/test_database.py", line 6, in <module>
from app import app, db, models
File "/Users/faiyamrahman/programming/Python/WebApps/NibsNWhiskeyFull/app/__init__.py", line 9, in <module>
from app import views, models
File "/Users/faiyamrahman/programming/Python/WebApps/NibsNWhiskeyFull/app/views.py", line 7, in <module>
from app.signup import user_datastore
File "/Users/faiyamrahman/programming/Python/WebApps/NibsNWhiskeyFull/app/signup.py", line 7, in <module>
security = Security(app, user_datastore)
File "/Users/faiyamrahman/programming/Python/WebApps/NibsNWhiskeyFull/flask/lib/python2.7/site-packages/flask_security/core.py", line 346, in __init__
self._state = self.init_app(app, datastore, **kwargs)
File "/Users/faiyamrahman/programming/Python/WebApps/NibsNWhiskeyFull/flask/lib/python2.7/site-packages/flask_security/core.py", line 368, in init_app
identity_loaded.connect_via(app)(_on_identity_loaded)
AttributeError: '_FakeSignal' object has no attribute 'connect_via'
我不知道这是什么意思。我试过阅读烧瓶安全文档,但我不明白为什么会这样。感谢任何对此进行尝试的人!