Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The method to retrieve information from the second form located in a different root using Python Flask is to create a separate route for the second form in the Flask application and then use the request object to retrieve the submitted data from the form.

Here is an example code:

from flask import Flask, request

app = Flask(__name__)

@app.route('/')
def index():
    return "<h1>Hello World!</h1>"

@app.route('/secondform', methods=['GET', 'POST'])
def second_form():
    if request.method == 'POST':
        data = request.form['input_field_name']
        # do something with the data

    return """
        <form method="POST" action="/secondform">
            <input type="text" name="input_field_name" />
            <input type="submit" value="Submit" />
        </form>
    """

if __name__ == '__main__':
    app.run(debug=True)

In this example, the second form is located at the /secondform URL. The second_form function handles this route and retrieves the submitted data using the request.form object. The submitted field is accessed using the name attribute of the input field (in this case, input_field_name).