Reputation: 3
I can't seem to get the right lines to use 2 forms I created on WTforms on the same html page:
I define these 2 forms
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")
and I want to display them in my Dashboard.html
page where I embedded the code to display them within 2 different form blocks.
then I try to create view function for my dashboard.html
where I call/define the 2 forms
@app.route('/dashboard.html')
def dashboard():
form = Area()
M_form = Message()
return render_template('dashboard.html',form= Area(),M_form = Message())
but I get a
M_form = Message()
NameError: global name 'Message' is not defined
I guess it must be some kind of basic, structural error, maybe I can t define 2 forms in my view but then how can i code this without having to resort to 2 different html pages (one for each form)?
Upvotes: 0
Views: 1730
Reputation: 11
Do from forms import Area, Message
at the top of your script.
Upvotes: 1