我正在尝试在flask 0.8 app中调试BuildError。尝试渲染多步形式的第2部分时,函数personal_open_account()
中发生错误。第1步呈现一个表单,如果已经过验证,则执行
return redirect(url_for('personal_open_account', step='2'))
。也就是说,它调用自身,但使用新的step
参数。第1步成功完成,表单被验证(我可以看到我输入的打印语句),但我立即收到BuildError:
Traceback (most recent call last):
File "/Users/sth/.virtualenvs/sb/lib/python2.7/site-packages/flask/app.py", line 1518, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/sth/.virtualenvs/sb/lib/python2.7/site-packages/flask/app.py", line 1506, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/sth/.virtualenvs/sb/lib/python2.7/site-packages/flask/app.py", line 1504, in wsgi_app
response = self.full_dispatch_request()
File "/Users/sth/.virtualenvs/sb/lib/python2.7/site-packages/flask/app.py", line 1264, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/sth/.virtualenvs/sb/lib/python2.7/site-packages/flask/app.py", line 1262, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/sth/.virtualenvs/sb/lib/python2.7/site-packages/flask/app.py", line 1248, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/sth/dev/sb_flask/sb/views/personal.py", line 333, in personal_open_account
return redirect(url_for('personal_open_account', step='2'))
File "/Users/sth/.virtualenvs/sb/lib/python2.7/site-packages/flask/helpers.py", line 208, in url_for
return ctx.url_adapter.build(endpoint, values, force_external=external)
File "/Users/sth/.virtualenvs/sb/lib/python2.7/site-packages/werkzeug/routing.py", line 1605, in build
raise BuildError(endpoint, values, method)
BuildError: ('personal_open_account', {'step': '2'}, None)
该功能本身如下:
@app.route('/personal/save/<product_type>/<slug>/open-account', methods=['GET', 'POST'])
def personal_open_account(product_type, slug):
...
答案 0 :(得分:0)
从查看代码可以很容易地推断出,后续调用中没有给出product_id和slug参数。
答案 1 :(得分:0)
@app.route('/personal/save/<product_type>/<slug>/open-account'
是一种创建api的错误方法。在这里,您有两个连续/<product_type>/<slug>/
的标识符,这是路由器不接受的。尝试重新编写此@app.route('/personal/save/<product_type>/slugs/<slug>/open-account'
之类的路线。