Reputation: 107
I was experimenting with FormAlchemy with django, flask, pyramid frameworks. Used SQLAlchemy==0.7 and FormAlchemy==1.4.2. Followed the documentation available online. However faced some strange problems. Did manage to get workaround, but dont understand why the rendering problem happened.
After passing form = FieldSet(User).render()
to jinja2 or mako renderer, the total automatically generated html form should be rendered in page, excluding the tag. However the template variables, ${form}
or {{ form }}
are not rendered as form. Instead they are plain text!!
Here's the view:
def index():
import formalchemy
from models import User
fs = formalchemy.FieldSet(User)
#fs.rebind(with_prefix=True)
opts=[('Google','1'),('Yahoo','2'),('MSN','3')]
fs.configure(options=[
fs.name.label('Full Name'),
fs.email.dropdown(opts)
])
form = fs
return render_template('form.html', form=form)
Here's the template:
{{ form.render() }}
Here's the output..!!:
Shouldn't it be a form?!...
This problem is not shown in latest version of FormAlchemy==1.5.5...but there it has another problem. The Email field options i used was a test. FormAlchemy==1.5.5 dont support or render the Option Select fields appropriately....That's why i chose version 1.4.2.
Anyone got any suggestions?
Upvotes: 0
Views: 107
Reputation: 3598
Try {{ form.render()|e }}
Read more http://jinja.pocoo.org/docs/dev/templates/#working-with-manual-escaping
Upvotes: -1