给出下面的路由,我发现如果参数test具有默认值,则当通过url_for用redirect]传递值时,它不会改变>。我想要的是在渲染模板时更改参数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传递值时,它不会改变。我想要更改...
尝试以下代码: