【发布时间】:2014-12-03 15:44:01
【问题描述】:
我正在编写一个简单的前端网页,它将接收一串单词并返回一个单词计数表。现在我可以查询字符串并将结果发布在同一页面上。但是,我想重定向并将结果发布到另一个页面上,应该是 @post(/'result')
下面是我的代码,但是,它一直给我一个错误提示:异常:
AttributeError ("'NoneType' object has no attribute 'split'",)
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/bottle.py", line 862, in _handle
return route.call(**args)
File "/Library/Python/2.7/site-packages/bottle.py", line 1729, in wrapper
rv = callback(*a, **ka)
File "frontEnd.py", line 16, in result
File "frontEnd.py", line 23, in query
for word in keyString.split():
AttributeError: 'NoneType' object has no attribute 'split'
我应该改变什么,以便在重定向页面 /result 上发布结果表而不会导致错误?
@get('/')
def search():
return '''<h1>Search</h1><form action="/" method="post"> Keyword:<input name="keywords"type="text"/><input value="GO" type="submit" /> </form>'''
@post('/')
def do_search():
redirect('/result')
@post('/result')
def result(wc,keyString):
keyString = request.forms.get('keywords')
wc = query(keyString)
return wordCountHTML(wc,keyString)
【问题讨论】: