<UnboundField(TextField, ('Study',), {})> 哪里出了问题?
<UnboundField(TextField, ('Study',), {})> where is the problem?
我是 Python 的新手,我想用 Wtforms 创建一个简单的页面,但是这段代码给我 UnboundField 错误。
有人可以帮我解决问题吗?
谢谢
from flask_wtf import Form
from wtforms import StringField
from wtforms import TextField
from wtforms import SelectField
from wtforms import RadioField
from wtforms import DecimalField
from wtforms import SubmitField
from datetime import datetime
from flask import render_template
from FlaskWebProject1 import app
class StudyManagementForm(Form):
"""This seemingly static class will be transformed
by the WTForms metaclass constructor"""
study = TextField("Study")
active = RadioField("Etude active")
submit = SubmitField("Ok")
def __init__(self):
print ('a')
@app.route('/')
@app.route('/study_management', methods=['GET', 'POST'])
def study_management():
submitForm = StudyManagementForm()
return render_template(
'study_management.html',
form = submitForm
)
我遇到了 UnboundField 错误:
<UnboundField(TextField, ('Study',), {})>
<UnboundField(RadioField, ('Etude active',), {})>
您有 class 继承:StudyManagementForm(Form)
但您选择通过这样做专门覆盖 __init__()
方法:
def __init__(self):
print('a')
这意味着 "seemingly static class will NOT be transformed" 因为所有这些代码现在都被避免了。相反:
def __init__(self):
super().__init__()
print('a')
现在将执行原始 Form.__init__()
,然后是您的打印语句。未绑定的字段将在该过程中绑定。
我是 Python 的新手,我想用 Wtforms 创建一个简单的页面,但是这段代码给我 UnboundField 错误。 有人可以帮我解决问题吗?
谢谢
from flask_wtf import Form
from wtforms import StringField
from wtforms import TextField
from wtforms import SelectField
from wtforms import RadioField
from wtforms import DecimalField
from wtforms import SubmitField
from datetime import datetime
from flask import render_template
from FlaskWebProject1 import app
class StudyManagementForm(Form):
"""This seemingly static class will be transformed
by the WTForms metaclass constructor"""
study = TextField("Study")
active = RadioField("Etude active")
submit = SubmitField("Ok")
def __init__(self):
print ('a')
@app.route('/')
@app.route('/study_management', methods=['GET', 'POST'])
def study_management():
submitForm = StudyManagementForm()
return render_template(
'study_management.html',
form = submitForm
)
我遇到了 UnboundField 错误:
<UnboundField(TextField, ('Study',), {})>
<UnboundField(RadioField, ('Etude active',), {})>
您有 class 继承:StudyManagementForm(Form)
但您选择通过这样做专门覆盖 __init__()
方法:
def __init__(self):
print('a')
这意味着 "seemingly static class will NOT be transformed" 因为所有这些代码现在都被避免了。相反:
def __init__(self):
super().__init__()
print('a')
现在将执行原始 Form.__init__()
,然后是您的打印语句。未绑定的字段将在该过程中绑定。