1

I am a newbie to flask and trying to make form submission with two webpages.

Basically, there are two webpages, in the app.py they are routed as

@app.route('/')
def index():
...
@app.route('/results', methods=['POST'])
def results():
...

There are one form submission on '/' and one on '/results'. Right now, clicking the button on '/' redirects the user to '/results', with the input text sent to '/results' as well

<form method=post action='/results'>
    <dl>                                                       
    {{ render_field(form.channel_title ) }}                    
    </dl>                                                      
    <input type=submit value='analyze' name='sumbit_btn'>      
</form>   

This part works. What I want to do now is to click the button on '/results' such that the text in its input form is used to update some text on itself. The problem is that in order to render '/results', input from '/' is needed.

def results():
    ....
    return render_template('results.html', channel=channel)

How can I implement this form submission on '/results' then, which send both its own form input and also the old input from '/' such that '/results' can be updated? Any suggestion is appreciated. Thanks.

1
  • 1
    Use an <input type="hidden" value="your stuff"/>. Commented Apr 27, 2016 at 13:09

1 Answer 1

1

You can add the data to the flask session.

from flask import Flask, session, abort, request, render_template

@app.route('/results', methods=['POST'])
def results():
    if request.form['channelname'] in ALLOWED_CHANNELS:
        session['channel'] = request.form['channelname']
    if 'channel' in session:
        return render_template('results.html', channel=session['channel'])
    else:
        abort(400)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.