WTForms 以 unicode 格式从表单中引入数据

WTForms bringing in data from form in unicode formating

出于某种原因,WTForms 正在获取 unicode 格式而非正常格式的信息。代码过去工作比重新启动时坏了。

flask视图错误:

TypeError

TypeError: 'unicode' object is not callable

控制台报错:

Traceback (most recent call last):

File "/Library/Python/2.7/site-packages/flask/app.py", line 1836, in call

return self.wsgi_app(environ, start_response)

File "/Library/Python/2.7/site-packages/flask/app.py", line 1820, in wsgi_app

response = self.make_response(self.handle_exception(e))

File "/Library/Python/2.7/site-packages/flask/app.py", line 1403, in handle_exception

reraise(exc_type, exc_value, tb)

File "/Library/Python/2.7/site-packages/flask/app.py", line 1817, in wsgi_app

response = self.full_dispatch_request()

File "/Library/Python/2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request

rv = self.handle_user_exception(e)

File "/Library/Python/2.7/site-packages/flask/app.py", line 1381, in handle_user_exception

reraise(exc_type, exc_value, tb)

File "/Library/Python/2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request

rv = self.dispatch_request()

File "/Library/Python/2.7/site-packages/flask/app.py", line 1461, in dispatch_request

return self.view_functionsrule.endpoint

File "/Users/marcellobachechi/Desktop/RMP/server.py", line 72, in hello

user = form.song.data()

TypeError: 'unicode' object is not callable

代码为:

class PickASong(Form):
    song = TextField(u'Song title', validators=[DataRequired()])

form = PickASong(csrf_enabled=False)

if form.validate_on_submit():
 user = form.song.data()

HTML:

<form action="" method="post" name="login">

      <p>
          {{ form.song(size=20) }}

      <input type="submit" value="Search!"></p></p>

     {{ form.song(size=20) }}
</form>

删除form.song.data后面的括号,因为它已经是Unicode字符串了。