Question

After finding this link http://wtforms.simplecodes.com/docs/1.0.2/specific_problems.html#dynamic-form-composition I am trying to add fields to my Form. I am using Google App Engine and Jinja2.

This is the code I'm using.

def build_form(form_json):
  class DynamicForm(wtforms.Form): pass                      
  d = DynamicForm
  name = "name"
  setattr(d, name, TextField(name.title()))
  return d

I send this to my jinja template. Within the template, I have this line:

<div>{{ new_form.name.label }}: {{ new_form.name }}</div>

Only the ':' shows up on the page itself.

When I look at the HTML source, I see this:

<div>: <UnboundField(TextField, ('Name',), {})></div>

Thanks for any insight.

Was it helpful?

Solution

You haven't instantiated the form, as shown in the code snippet you link to. d is the class, not the instance of it.

form = d()

or if it's a POST:

form = d(request.POST)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top