0
我似乎无法得到正确的线条中使用的2种形式我对WTforms创建相同的HTML页面上的多个形式:烧瓶wtforms相同的HTML页面
我定义这2种形式
class Area(Form):
title = TextField("Title", [validators.Required("Please enter an Area Title")])
text = TextAreaField("Text (max 50 characters)",[validators.Required("Please enter a Push text"),validators.Length(max=50,message="Area text cannot be more than 50 characters")])
class Message(Form):
Message_title = TextField("Title", [validators.Required("Please enter a Message Title")])
Message_Date_and_Time = DateTimeField("Date and Time")
我想在我的Dashboard.html
页面中显示它们,我在其中嵌入代码以在2个不同的表单块中显示它们。
然后我尝试了我的dashboard.html
,我打电话/定义2种形式
@app.route('/dashboard.html')
def dashboard():
form = Area()
M_form = Message()
return render_template('dashboard.html',form= Area(),M_form = Message())
创建视图的功能,但我得到一个
M_form = Message()
NameError: global name 'Message' is not defined
我想这一定是某种基本的,结构错误,也许我不能在我的视图中定义2个表单,但是如何在不必诉诸2个不同的html页面(每个表单一个)的情况下编码这个表单?
在您定义路线的地方是否输入了“Message”类? – bheklilr
检查你是否在你的文件中导入了消息类 –
谢谢你,这很简单,我猜...我不知道为什么,但我想所有存储在我的forms.py中的类(我保留我的表单)已经从Forms导入 – Hoyt