I'm trying to debug a BuildError in a flask 0.8 app. The error occurs in the function personal_open_account()
while trying to render part 2 of a multi-step form. Step 1 renders a form, and if it's validated, performs
return redirect(url_for('personal_open_account', step='2'))
. That is, it calls itself, but with a new step
parameter. Step 1 completes successfully, and the form is validated (I can see a print statement I put in), but I then immediately receive a 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)
The function itself looks like:
@app.route('/personal/save/<product_type>/<slug>/open-account', methods=['GET', 'POST'])
def personal_open_account(product_type, slug):
...
@app.route('/personal/save/<product_type>/<slug>/open-account'
是创建api的错误方法。在这里,您有两个连续的/<product_type>/<slug>/
路由器不接受。请尝试改写类似@app.route('/personal/save/<product_type>/slugs/<slug>/open-account'
的路由。
从查看代码可以轻松推断出,在随后的调用中没有给出product_id和slug参数。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.