Skip to content

Instantly share code, notes, and snippets.

@huahu
Created August 28, 2013 05:37
Show Gist options
  • Save huahu/6362470 to your computer and use it in GitHub Desktop.
Save huahu/6362470 to your computer and use it in GitHub Desktop.
from wtforms import Form
定义一个类,目的用于获取html的form中的值
class RegistrationForm(Form):
name = TextField('name', [validators.Length(min=4, max=25)])
这个是处理方法,目的是打印获取的值
class ReciveData(RequestHandler):
def post(self):
form = RegistrationForm()
name = form.name.data
self.write('Hello %s' %name)
总是报以下错误:
[root@huahu sjianbing]# python runs.py 192.168.112.147
WARNING:tornado.access:404 GET /img/open_fst_20110124zzjs_net.gif (192.168.112.1) 2.72ms
WARNING:tornado.access:404 GET /img/line_y_20110124zzjs_net.gif (192.168.112.1) 1.80ms
WARNING:tornado.access:404 GET /img/t_20110124zzjs_net.gif (192.168.112.1) 2.25ms
ERROR:tornado.application:Uncaught exception POST /huahu (192.168.112.1)
HTTPRequest(protocol='http', host='192.168.112.147', method='POST', uri='/huahu', version='HTTP/1.1', remote_ip='192.168.112.1', headers={'Content-Length': '16', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Host': '192.168.112.147', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0', 'Connection': 'keep-alive', 'Referer': 'http://192.168.112.147/', 'Content-Type': 'application/x-www-form-urlencoded'})
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/tornado-3.1-py2.7.egg/tornado/web.py", line 1141, in _when_complete
callback()
File "/usr/local/lib/python2.7/site-packages/tornado-3.1-py2.7.egg/tornado/web.py", line 1162, in _execute_method
self._when_complete(method(*self.path_args, **self.path_kwargs),
File "/opt/sjianbing/handlers/index.py", line 33, in post
form = SampleForm(self)
File "/usr/local/lib/python2.7/site-packages/WTForms-1.0.4-py2.7.egg/wtforms/form.py", line 178, in __call__
return type.__call__(cls, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/WTForms-1.0.4-py2.7.egg/wtforms/form.py", line 233, in __init__
self.process(formdata, obj, **kwargs)
File "/usr/local/lib/python2.7/site-packages/WTForms-1.0.4-py2.7.egg/wtforms/form.py", line 102, in process
raise TypeError("formdata should be a multidict-type wrapper that supports the 'getlist' method")
TypeError: formdata should be a multidict-type wrapper that supports the 'getlist' method
@huahu
Copy link
Author

huahu commented Aug 28, 2013

1.你这个form跟request没什么关联
2.tornado跟wtforms要集成一下先 不是拿过来就用的
tornado的参数不符合wtforms的需求 需要转换一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment