我正在按照本教程学习如何使用stormpath和本教程(https://stormpath.com/blog/build-a-flask-app-in-30-minutes)在flask上创建一个缺少此功能的用户身份验证系统;在试用它并感受到内容之后,我尝试通过设置
来调查启用注册app.config['STORMPATH_ENABLE_REGISTRATION'] = False
在flaskr.py文件中为True;启用默认的stormpath注册页面,但在连接到localhost / register时,它给了我这个长时间的错误,我无法做出正面或反面:
Traceback (most recent call last):
File "C:\Python35-32\lib\site-packages\flask\app.py", line 1994, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Python35-32\lib\site-packages\flask\app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "C:\Python35-32\lib\site-packages\flask\app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Python35-32\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Python35-32\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "C:\Python35-32\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Python35-32\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Python35-32\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Python35-32\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Python35-32\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Python35-32\lib\site-packages\flask_stormpath\views.py", line 39, in register
form = RegistrationForm(config=current_app.config)
File "C:\Python35-32\lib\site-packages\wtforms\form.py", line 212, in __call__
return type.__call__(cls, *args, **kwargs)
File "C:\Python35-32\lib\site-packages\flask_stormpath\forms.py", line 40, in __init__
**kwargs)
File "C:\Python35-32\lib\site-packages\flask_wtf\form.py", line 158, in __init__
super(Form, self).__init__(*args, **kwargs)
TypeError: __init__() takes from 1 to 2 positional arguments but 7 were given
我完全不知道出了什么问题,我在文档或类似错误中找不到任何内容。
答案 0 :(得分:0)
当你遇到Python堆栈跟踪时,从底部开始并逐步完成:
form.py
这表示form.py
中的函数使用不正确。由于 File "C:\Python35-32\lib\site-packages\flask_stormpath\views.py", line 39, in register
form = RegistrationForm(config=current_app.config)
File "C:\Python35-32\lib\site-packages\wtforms\form.py", line 212, in __call__
return type.__call__(cls, *args, **kwargs)
File "C:\Python35-32\lib\site-packages\flask_stormpath\forms.py", line 40, in __init__
**kwargs)
File "C:\Python35-32\lib\site-packages\flask_wtf\form.py", line 158, in __init__
super(Form, self).__init__(*args, **kwargs)
TypeError: __init__() takes from 1 to 2 positional arguments but 7 were given
是flask-wtf的一部分,你不太可能修改它(我希望!),继续上去:
RegistrationForm(config=current_app.config)
此处候选人的可能性更大:views.py
第39行的config=current_app.config
被错误地调用或者WTForms没有预料到的方式。它可能是views.py
。
如果可能的话,从表单 s .py导入应用程序配置中的变量,并在{{1}}中使用之前进行表单配置。
答案 1 :(得分:0)
发生错误是因为您使用的是Flask-WTF版本0.14或更高版本(此版本中引入了一些与先前版本不兼容的更改)。这解释了为什么stacktrace提到了pNode := pDocument.DocumentElement;
:
flask_wtf
此问题已在stormpath-flask的File "C:\Python35-32\lib\site-packages\flask_wtf\form.py", line 158, in __init__
super(Form, self).__init__(*args, **kwargs)
TypeError: __init__() takes from 1 to 2 positional arguments but 7 were given
分支中修复,但尚未发布。如果您不能等待正式发布,请查看详细更改in this pull request。要解决此问题,只需在本地flask-stormpath安装中实现pull请求中develop
中显示的更改。
所以在你的情况下,你会:
flask_stormpath/forms.py
cd
C:\Python35-32\lib\site-packages\flask_stormpath
目录(我们根据你收到的堆栈跟踪知道这个。)
打开forms.py
并进行拉取请求中显示的更改
上面链接
有关该主题的讨论,请参阅here。