Python 自动重定向

Python 自动重定向,python,flask,Python,Flask,我发现一个错误: werkzeug.routing.BuildError:无法为端点“foo.bar,id=1”生成url。你是说“foo.bar”吗 foobp= Blueprint('foo', __name__) @foobp.route('/bar/<id>', , methods=['get', 'post']) def bar(id): id_var = id form = SomeForm() if form.validate_on_submi

我发现一个错误:

werkzeug.routing.BuildError:无法为端点“foo.bar,id=1”生成url。你是说“foo.bar”吗

foobp= Blueprint('foo', __name__)

@foobp.route('/bar/<id>', , methods=['get', 'post'])
def bar(id):
    id_var = id
    form = SomeForm()
    if form.validate_on_submit():
        # do database stuff
        return redirect(url_for('foo.bar, id={}'.format(id_var)))
    # do some other stuff
    return render_template('bar'html, form=form, ...)
foobp=Blueprint('foo',\uuuuu name\uuuuu)
@route('/bar/',方法=['get','post'])
def条(id):
id_var=id
form=SomeForm()
if form.validate_on_submit():
#做数据库工作
返回重定向(url_for('foo.bar,id={}.format(id_var)))
#做些别的事情
返回呈现模板('bar'html,form=form,…)
我试着去掉
'foo.bar'
,只做
'bar'
,但这似乎也不起作用

我做错了什么?

试试这个:

return redirect(url_for('foo.bar', id=id_var))

在路由定义中也有两个逗号。

我还尝试了相对重定向
'.bar'
返回重定向(url\u for('.bar',id=id))
,用于在html模板中而不是视图中执行url\u。是的,这两个逗号是一种类型!很抱歉。