定义WTFoms表单引发TypeError:调用元类库时出错

时间:2016-05-24 15:15:04

标签: python flask wtforms

我正在尝试使用Flask-WTF定义一个简单的表单。我得到TypeError: Error when calling the metaclass bases。为什么我会收到此错误?

from flask_wtf import form

class RegisterForm(form):
    pass
Traceback (most recent call last):
  File "manage.py", line 5, in <module>
    from flask_init import app
  File "/Users/sapp/Desktop/ude/flask_init/__init__.py", line 12, in <module>
    from author import views
  File "/Users/sapp/Desktop/ude/flask_init/author/views.py", line 3, in     <module>
    from form import RegisterForm
   File "/Users/sapp/Desktop/ude/flask_init/author/form.py", line 5, in <module>
    class RegisterForm(form):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)

1 个答案:

答案 0 :(得分:1)

您导入了模块form并将其作为RegisterForm的基类传递。模块不是有效的基类。您正在寻找form.Form,该模块中的课程Form

from flask_wtf.form import Form

class RegisterForm(Form):
    pass