总是使用默认函数参数进行Flask重新路由

问题描述 投票:0回答:1

给出下面的路由,我发现如果参数test具有默认值,则当通过url_forredirect]传递值时,它不会改变>。我想要的是在渲染模板时更改参数test,具体取决于是否刚刚提交了表单。

@app.route('/view_story/<story_id>', methods=['GET', 'POST'])
def view_story(story_id, test='no'):
    ...
    if current_user.is_authenticated:
        if request.method == 'POST':
            #Add stuff to database from the form. 
            return redirect(url_for('view_story', story_id=story_id, test='yes'))

    return render_template('story.html', test=test)

考虑到下面的路由,我发现如果我为参数test设置了默认值,则在通过带有重定向的url_for传递值时,它不会改变。我想要更改...

flask routing
1个回答
0
投票

尝试以下代码:

© www.soinside.com 2019 - 2024. All rights reserved.