0

In python flask, I want to change value obtained by POST method for redirect other route.

@app.route('/nextpage', methods=['POST'])
def nextpage():
    page = int(request.form['page'])
    page = cb.next_page(page)

    return redirect(url_for('community'), code = 307)

from this code, the 'page' variable is changed to the value returned by cb.next_page(page)

@app.route('/community', methods=['POST'])
def community():
    page = int(request.form['page'])
    docs, page = cb.show(page)

    return render_template('community.html', posts = docs, ID = ID, page = page)

and in this route, i want request.form['page'] be the value recieved by cb.next_page(page), not the same value as the first.

How can I do it without changing the method to 'GET'? Please help.

davidism
  • 121,510
  • 29
  • 395
  • 339
SOL
  • 3
  • 2

1 Answers1

0

may be this example helps

@app.route('/nextpage', methods=['POST'])
def nextpage():
    page = int(request.form['page'])
    page = cb.next_page(page)

    return redirect(url_for('community', page=page), code = 307)
@app.route('/community', methods=['POST'])
def community():
    page = request.args.get('page')
    docs, page = cb.show(page)

    return render_template('community.html', posts = docs, ID = ID, page = page)

Simplecode
  • 559
  • 7
  • 19