开发者

WTForms won't render fields

I'm having trouble rendering my form's fields with WTForms. I'm using it with the webapp framework and Django templates in GAE.

I've made a simple project as test and it worked fine. Here's some code from a larger project, the one with the problem:

class ShowBoardForm(Form):
    name = TextFie开发者_开发知识库ld('Name', [validators.Length(max=20)])
    email = TextField('Email', [validators.Length(max=20)])
    subject = TextField('Subject', [validators.Length(max=20)])
    textfield = TextAreaField('Comment', [validators.Length(max=2000)])
    filefield = FileField('Image')

And here's a snippet of the form class being used in a request handler (I ommited some irrelevant code):

template_vars = {
    'form':ShowBoardForm()
}

path = os.path.join(os.path.dirname(__file__),'templates','showboard.html')
self.response.out.write(template.render(path,template_vars))

Here's how I'm using form in the template:

...
<form method='post' action='{{ url }}/post' enctype='multipart/form-data'>
{{ form.name.label }}{{ form.name }}<br/>
{{ form.email.label }}{{ form.email }}<br/>
{{ form.subject.label }}{{ form.subject }}<br/>
{{ form.textfield.label }}{{ form.textfield }}<br/>
{{ form.filefield.label }}{{ form.filefield }}<br/>
<input type='submit' value='ok'/>
</form>
...

The problem is that instead of giving me the HTML representation of the field, form.name, form.email, etc... in the template has this kind of output: <form.TextField instance at 0xac261ec> or <form.TextAreaField instance at 0x966e76c>, etc... I did the same thing in the test project I mentioned, and it seems to work just fine. What can be going wrong here?


I figured it out. Turns out I had another module defining a Form, TextField, and TextAreaField class, that was being used in place of WTForms classes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜